Answer the question
In order to leave comments, you need to log in
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
)
from django.urls import path
from .views import *
urlpatterns = [
path('text/', text),
path('time/', time),
]
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)
Answer the question
In order to leave comments, you need to log in
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.
The order of elements in urlpatterns matters. First more specific, then less.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question