Answer the question
In order to leave comments, you need to log in
How to fix url issue in Django?
Hello.
Made an index page, worked in django for a while.
Recently this problem started: I create any application or just want to add 1 more url, Django shows 404 Not found.
There is even the simplest code to add:
views:
from django.shortcuts import render, render_to_response
from django.http import HttpResponse
from django.contrib.auth import authenticate
def reg(request):
if request.user.is_authenticated():
return HttpResponse("Вы уже зареганы")
else:
return HttpResponse("Пора бы зарегаться")
from django.conf.urls import url
from . import views
urlpatterns = [
url(r'^reg/', views.reg, name='reg'),
]
urlpatterns = [
url(r'^$', include('index.urls')),
url(r'^reg/', include('registration.urls')),
url(r'^admin/', include(admin.site.urls)),
url(r'^usr/', include('profile_page.urls')),
]\
+ static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)\
+ static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
Answer the question
In order to leave comments, you need to log in
First, the sign ^
means "begins with" and it will kill any url included via include. Secondly, urls should be "closed" with the sign$
url(r'reg/$', views.reg, name='reg'),
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question