Я использую Django-Filer в качестве администратора в веб-проекте Django, который размещен в PythonAnywhere. Я прошел инструкции по установке, но у меня возникают проблемы с доступом к каноническим URL-адресам, которые Filer создает для каждого файла. Кажется, меня перенаправляют на расширенный URL, который Filer.urls не распознает (неканоническая часть начинается с / filer-public /; это каталог, который создается и хранит мои файлы в отдельном каталоге файлов PythonAnywhere) .
Есть ли ошибка в моем синтаксисе URL? Ошибка в моих представлениях. Канонический? Я не уверен, почему подключение точного канонического URL перенаправляет меня на эту расширенную версию URL.
Python: 3,7
Джанго: 2,2
Канонический URL:
/ Filer / обмен / 1560887480/39 /
ЭКРАН ОШИБКИ / ОТЛАДКИ
Page not found (404)
Request Method: GET
Request URL: http://www.mywebsite.com/filer/sharing/1560887480/39/filer_public/36/ea/36ea58a8-f59c-41ad-9d1f-00a976603eb1/big1.jpg
Using the URLconf defined in mywebsitesite.urls, Django tried these URL patterns, in this order:
admin/
^filer/ sharing/(?P<uploaded_at>[0-9]+)/(?P<file_id>[0-9]+)/$ [name='canonical']
The current path, filer/sharing/1560887480/39/filer_public/36/ea/36ea58a8-f59c-41ad-9d1f-00a976603eb1/big1.jpg, didn't match any of these.
APP URL: /mywebsite/.virtualenvs/env/lib/python3.7/site-packages/filer/urls.py
# -*- coding: utf-8 -*-
from __future__ import absolute_import
from django.conf.urls import url
from . import settings as filer_settings
from . import views
urlpatterns = [
url(
filer_settings.FILER_CANONICAL_URL + r'(?P<uploaded_at>[0-9]+)/(?P<file_id>[0-9]+)/$', # flake8: noqa
views.canonical,
name='canonical'
),
]
APP VIEWS: /mywebsite/.virtualenvs/env/lib/python3.7/site-packages/filer/VIEWS.py
# -*- coding: utf-8 -*-
from __future__ import absolute_import, unicode_literals
from django.http import Http404
from django.shortcuts import get_object_or_404, redirect
from .models import File
def canonical(request, uploaded_at, file_id):
"""
Redirect to the current url of a public file
"""
filer_file = get_object_or_404(File, pk=file_id, is_public=True)
if (not filer_file.file or int(uploaded_at) != filer_file.canonical_time):
raise Http404('No %s matches the given query.' % File._meta.object_name)
return redirect(filer_file.url)
ОСНОВНЫЕ URL-адреса: /home/mywebsite/mywebsite/urls.py
from django.contrib import admin
from django.urls import include, path
from django.conf.urls import url
from django.views.generic import TemplateView
from quotes.views import Register
urlpatterns = [
path('admin/', admin.site.urls),
path('', include('django.contrib.auth.urls')),
path('', include('pages.urls')),
url(r'^filer/', include('filer.urls')),
]
БАЗОВЫЕ НАСТРОЙКИ: /home/mywebsite/mywebsite/settings.py
FILER_CANONICAL_URL = 'sharing/'