Django adds "index" to empty url - python

I am just learning Django. I can't understand why "index" is being added to the empty URL. I need the address to be http://127.0.0.1:8000/, but in the address bar it immediately changes to http://127.0.0.1:8000/index/.
However, if I enter http: // localhost: 8000 / there are no such problems.
urls.py
from django.contrib import admin
from django.urls import path
from django.conf.urls.static import static
from django.conf import settings
from django.urls import include
from about import views
urlpatterns = [
path('admin/', admin.site.urls),
path('', include('about.urls')),
path('ckeditor/', include('ckeditor_uploader.urls')),
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
about app urls
from django.urls import path, re_path
from django.views.generic import RedirectView
from . import views
urlpatterns = [
path('', views.index, name='index'),
]

The solution was very simple, it was necessary to clear the browser cache :)

Related

Django url template tag ovrwrite the last letter of the base address

When using the URL template tag I checked the source code of the html page and the url appears missing the last letter of the base address, see an example:
...
<li>Products</li>
...
returns
...
<li>Products</li>
...
but the the base address is my-site.com/deck
...
so, why dont returns
...
<li>Products</li>
...
I checked my settings.py and urls.py and didn't see anything wrong, I don't know where else to look
my urls.py
from django.conf import settings
from django.conf.urls.static import static
from django.contrib import admin
from django.urls import include, path, re_path
urlpatterns = [
path('admin/', admin.site.urls),
path('', include('principal.urls')),
path('product/', include('products.urls'), name='product'),
] + static(settings.MEDIA_URL, document_root=settings.STATIC_ROOT)
and the urls.py from app product
from django.urls import path
from . import views
urlpatterns = [
path('', views.ProductHTMxTableView.as_view(), name='products'),
path('product/<int:pk>', views.ProductDetail.as_view(), name='product_detail'),
path('show/', views.ProductShow.as_view(), name='product_show'),
]

django path to view

hey i have a url path that i want to lead me to an application url file
but it says page not found
here is my core url:
from django.contrib import admin
from django.urls import path, include
from django.conf import settings
from django.conf.urls.static import static
urlpatterns = [
path('admin/', admin.site.urls),
path('', include('store.urls', namespace='store')),
path('basket/', include('basket.urls', namespace='basket')),
]
if settings.DEBUG:
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
and here is my basket.url file:
from django.urls import path
from . import views
app_name = 'basket'
urlpatterns = [
path('', views.basket_summary, name='basket_summary'),
]
and this is the view:
from django.shortcuts import render
# Create your views here.
def basket_summary(request):
return render(request, 'store/basket/summary.html')
my app name is basket , and i might add all of the files are defined.
whats the problem ?
You should add a trailing slash after /basket/.
Read more about APPEND_SLASH in the official documentation.

url issues with django

I can't get my urls to work for django no matter what I try
from django.contrib import admin
from django.urls import include, re_path
from django.conf.urls import url
from catalog import views
urlpatterns = [
re_path(r'^admin/', admin.site.urls),
re_path(r'^fruit/?$', views.fruit_catalogue, name='fruit_catalogue'),
re_path(r'^fruit/?$', views.fruit_details),
re_path(r'^fruit/(?P<fruit_id>[1-7]{1})/?$', views.fruit_details),
]
There are 2 url.py files that you should check for the correct functioning of the URLs.
First the one, that is in your project, that should look something like this:
from django.contrib import admin
from django.urls import include, path
from django.conf import settings
urlpatterns = [
path('admin/', admin.site.urls),
path("", include("NAMEOFAPP.urls")),
]
and the other is inside your app. and a simple version of it should look something like this:
from django.urls import path
from . import views
urlpatterns = [
path("home", views.index, name="index"),
path("login", views.login_view, name="login"),
path("register", views.register, name="register")
]
Try to use this same setup and you should be perfectly fine.

django in production enviorment, urls.py only matching empty path i.e " " and nothing else?

Everything works fine on development server but in production server I can only access views.home at https://www.host.com/ and everything else such as
https://www.host.com/b/ or https://www.host.com/tab or https://www.host.com/ext returns status_code 500.
I'm using django 2.1 in python 3.7. Cheers!
Here's the project level urls.py
from django.contrib import admin
from django.urls import path, include
from django.contrib.auth import views as auth_views
from ext.forms import CustomAuthForm
from mysite import settings
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
urlpatterns = [
path('admin/', admin.site.urls),
path('login/', auth_views.LoginView.as_view(authentication_form = CustomAuthForm), name='login'),
path('logout/', auth_views.LogoutView.as_view(next_page= settings.LOGOUT_REDIRECT_URL), name='logout'),
path('', include('ext.urls')),
]
urlpatterns += staticfiles_urlpatterns()
And app level urls.py looks like this
from django.urls import path, re_path
from django.conf.urls import url
from ext import views
from django.contrib import admin
from django.conf import settings
from django.conf.urls.static import static
app_name = 'ext'
urlpatterns = [
path('', views.home, name='home'),
path('int/', views.get_int_status, name='home-load-int'),
path('ext/', views.get_ext_status, name='home-load-ext'),
path('tab/', views.get_tab_status, name='home-load-tab'),
path('b/', views.uzair, name='home-uzair'),
]
I was missing RewriteEngine On in my .httaccess file, what a shame xD

Django URL Does not Exist?

This is very strange, any ideas?:
Here is my code for urls.py
from django.contrib import admin
from django.conf.urls import include
from django.urls import path
urlpatterns = [
path('admin/', admin.site.urls),
path('videos/', include('videos.urls'))
]
And videos/urls.py:
from django.urls import path
from . import views
urlpatterns = [
path(r'^$', views.index, name='index'),
]
Actually, I fixed it! Simple mistake. Change videos\urls.py to this;

Categories

Resources