A
A
Artem Seleznev2018-03-10 23:34:24
Django
Artem Seleznev, 2018-03-10 23:34:24

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("Пора бы зарегаться")

url in application:
from django.conf.urls import url
from . import views
urlpatterns = [
    url(r'^reg/', views.reg, name='reg'),
]

url in the main file:
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)

It seems to be simple, but still: Page not found (404)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Gornostaev, 2018-03-11
@seleznev_artem_info

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 question

Ask a Question

731 491 924 answers to any question