BotaniQ_Q
@BotaniQ_Q

Не работают динамические url-ы в Django?

Читаю Django book, делаю пример с этой страницы
https://rtfm.co.ua/django-book-trete-predstavlenie...
Вот мой urls.py
from django.conf.urls import url
from django.contrib import admin
from views import hours_ahead


urlpatterns = [
    url(r'^admin/', admin.site.urls),
   	url(r'^time/plus/d+/$', hours_ahead),


]

вот views
from django.http import HttpResponse
import datetime

def hours_ahead(request, offset):
    try:
        offset = int(offset)
    except ValueError:
        raise Http404()
    dt = datetime.datetime.now() + datetime.timedelta(hours=offset)
    html = "<html><body>In %s hour(s), it will be %s.</body></html>" % (offset, dt)
    return HttpResponse(html)

При попытке ввести в браузере адресс
сайт//time/plus/3/ выводится ошибка Page not found (404), почему?
вот вся ошибка:
spoiler
Page not found (404)
Request Method: GET
Request URL: 127.0.0.1:8000/time/plus/1
Using the URLconf defined in first.urls, Django tried these URL patterns, in this order:
^admin/
^time/plus(\d+)/$
The current path, time/plus/1/, didn't match any of these.
You're seeing this error because you have DEBUG = True in your Django settings file. Change that to False, and Django will display a standard 404 page.
  • Вопрос задан
  • 354 просмотра
Решения вопроса 1
aRegius
@aRegius
Python Enthusiast
1. \d+
2. (\d+)
3. Это пример из книги 2009 года выпуска (Django 1.1)... Оно вам надо? :)
Ответ написан
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы