Skip to content

Instantly share code, notes, and snippets.

@AABur
Last active October 3, 2021 10:45
Show Gist options
  • Select an option

  • Save AABur/60a40799c392bdfdcadfebcff5f7f040 to your computer and use it in GitHub Desktop.

Select an option

Save AABur/60a40799c392bdfdcadfebcff5f7f040 to your computer and use it in GitHub Desktop.

San Sanych Yesterday at 00:50

Делаю 4 проект (Django)

На 3ем шаге. Уже есть форма регистрации, логин, список пользователей. Всё работало до...

Установил локально проект для образца вот из этого гайда Django Tutorial: The Local Library website https://developer.mozilla.org/en-US/docs/Learn/Server-side/Django сам проект https://github.com/mdn/django-locallibrary-tutorial

форк,
клон,
venv
затем по инструкции из README
pip3 install -r requirements.txt
python3 manage.py makemigrations
python3 manage.py migrate
python3 manage.py collectstatic
python3 manage.py test # Run the standard tests. These should all pass.
python3 manage.py createsuperuser # Create a superuser
python3 manage.py runserver

Отлично работает. Теперь возвращаюсь к своему 4му проекту. Только что всё работало. Запускаю python3 manage.py runserver И мой проект не работает. При обращении к локальному серверу http://127.0.0.1:8000/ получаю

Page not found (404)
Request Method:	GET
Request URL:	http://127.0.0.1:8000/catalog/

В консоли при этом так

❯ py manage.py runserver
Watching for file changes with StatReloader
Performing system checks...

System check identified no issues (0 silenced).
October 02, 2021 - 01:45:48
Django version 3.2.7, using settings 'task_manager.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
Not Found: /catalog/
[02/Oct/2021 01:45:50] "GET /catalog/ HTTP/1.1" 404 4613

И вот это вот самое /catalog/ оно вот из того самого Django Tutorial: The Local Library website Как оно попало в мой 4й проект, и как его теперь от туда выкорчевать НЕ ПОНИМАЮ! Плиз хелп!!! Куда копать?

Valentin Khomutenko 15 hours ago

Да, тут косяк того приложения из django tutorial. Оно делает редирект с / на /catalog/ со статусом 301 (moved permanently)

➜  django-locallibrary-tutorial git:(master) ✗ py manage.py runserver
Watching for file changes with StatReloader
Performing system checks...

System check identified no issues (0 silenced).
October 02, 2021 - 19:35:53
Django version 3.1.2, using settings 'locallibrary.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
[02/Oct/2021 19:36:02] "GET / HTTP/1.1" 301 0
➜  ~ curl -v http://127.0.0.1:8000/
*   Trying 127.0.0.1...
* TCP_NODELAY set
* Connected to 127.0.0.1 (127.0.0.1) port 8000 (#0)
> GET / HTTP/1.1
> Host: 127.0.0.1:8000
> User-Agent: curl/7.64.1
> Accept: */*
>
< HTTP/1.1 301 Moved Permanently
< Date: Sat, 02 Oct 2021 19:36:12 GMT
< Server: WSGIServer/0.2 CPython/3.9.7
< Content-Type: text/html; charset=utf-8
< Location: /catalog/
< X-Frame-Options: DENY
< Content-Length: 0
< X-Content-Type-Options: nosniff
< Referrer-Policy: same-origin
<
* Connection #0 to host 127.0.0.1 left intact
* Closing connection 0

Ответы 301 браузеры активно кэшируют в отличие от 302

Чистка кэша должна помочь. Еще можно в locallibrary/urls.py убрать флаг permanent, чтобы потом не мучиться с этим

#Add URL maps to redirect the base URL to our application
from django.views.generic import RedirectView
urlpatterns += [
    path('', RedirectView.as_view(url='/catalog/', permanent=False)),
]

Отчистка кеша помогла. Про redirect permanent понял. Спасибо большое. Сам бы точно не докопался

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment