0
0
0ldn0mad2020-07-29 14:15:03
Django
0ldn0mad, 2020-07-29 14:15:03

What's wrong with Django routes?

Good afternoon.
Tell me what's wrong with my Django routes?
Here is the urls.py of the project:

from django.conf import settings
from django.conf.urls.static import static
from django.contrib import admin
from django.urls import path, include


urlpatterns = [
    # path('admin/', admin.site.urls),
    path('', include('main.urls')),
    path('text/', include('news.urls')),
    path('time/', include('news.urls')),
]

if settings.DEBUG:
    urlpatterns += static(
        settings.MEDIA_URL,
        document_root=settings.MEDIA_ROOT
    )


This is the urls.py of the application:
from django.urls import path
from .views import *

urlpatterns = [
    path('text/', text),
    path('time/', time),
]


And the application controller:
from django.shortcuts import render
from django.http import HttpResponse
import datetime

# Create your views here.

def text(request):
    return HttpResponse("Страница новостей")

def time(request):
    now = datetime.datetime.now()
    html = "<html><body>It is now %s.</body></html>" % now
    return HttpResponse(html)

The main page at the link: 127.0.0.1:8000 opens, data is transmitted.
And the links:
127.0.0.1:8000/news/text and 127.0.0.1:8000/news/time do not open.
What's wrong?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dr. Bacon, 2020-07-29
@0ldn0mad

where is "news" in path? and why include('news.urls') twice? It looks more like they didn’t figure out how it all works, re-read the docs again.

S
Sergey Gornostaev, 2020-07-29
@sergey-gornostaev

The order of elements in urlpatterns matters. First more specific, then less.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question