gpt4 book ai didi

python - Django-Filer 规范 URL 无法正常工作(找不到页面)

转载 作者:行者123 更新时间:2023-12-01 07:41:58 50 4
gpt4 key购买 nike

我在我的管理员中的 Django Web 项目中使用 Django-Filer,该项目托管在 PythonAnywhere 中。我已阅读安装说明,但无法访问 Filer 为每个文件创建的规范 URL。似乎我被定向到 Filer.urls 无法识别的扩展 url(非规范部分从/filer-public/开始;这是一个正在创建的目录,并将我的文件存储在单独的 PythonAnywhere 文件目录中) .

我的网址语法是否有错误?我的观点有错误。规范吗?我不确定为什么插入确切的规范 URL 会将我重定向到该 URL 的扩展版本。

Python:3.7 Django :2.2

规范 URL:/filer/sharing/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.

应用程序网址:/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'
),
]

应用 View :/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)

基本网址:/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/'

最佳答案

我能够通过在我的 url 和设置文件中配置静态和媒体根来使规范 url 正常工作,如下所示。

urls.py

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

urlpatterns = [
path('admin/', admin.site.urls),
path('', include('django.contrib.auth.urls')),
url(r'^filer/', include('filer.urls')),
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

settings.py

MEDIA_ROOT = os.environ.get('FILER_MEDIA_ROOT', os.path.join(BASE_DIR, 'media'))

MEDIA_URL = '/home/mywebsite/media/'

关于python - Django-Filer 规范 URL 无法正常工作(找不到页面),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56657142/

50 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com