使用 django-allauth 时 Django 无法找到静态文件

发布于 2024-12-20 04:38:15 字数 489 浏览 2 评论 0原文

当我使用 allauth 时,一切似乎都工作正常,除了 Django 现在无法找到静态文件。如果没有 allauth,所有静态文件都会被渲染。 allauth 的设置需要添加

TEMPLATE_CONTEXT_PROCESSORS = (

    "allauth.context_processors.allauth",
    "allauth.account.context_processors.account"
)

我之前的设置文件中没有 TEMPLATE_CONTEXT_PROCESSORS 。我有什么遗漏的吗?我该如何解决这个问题呢。当我看到 DEBUG 控制台时,我可以看到它正在尝试获取 css 文件,而

"GET /accounts/login/css/contact.css"

它应该这样做

"GET /static/css/contact.css"

When I use allauth, everything seems to work fine except that Django is now unable to find the static files. Without allauth all the static files are being rendered. the settings for allauth requires to add

TEMPLATE_CONTEXT_PROCESSORS = (

    "allauth.context_processors.allauth",
    "allauth.account.context_processors.account"
)

I did not have TEMPLATE_CONTEXT_PROCESSORS in my settings file earlier. Is there something that I am missing? How should I solve this problem. When I see the DEBUG console I can see it is trying to fetch the css file as

"GET /accounts/login/css/contact.css"

whereas it should be doing

"GET /static/css/contact.css"

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

奈何桥上唱咆哮 2024-12-27 04:38:15

TEMPLATE_CONTEXT_PROCESSORS 有一个默认值,您将覆盖该值。所以现在默认的已经丢失了。其中之一是“django.core.context_processors.static”,这就是 Django 找不到您的静态文件的原因。

请参阅 https://docs.djangoproject.com/en/1.3 /ref/settings/#template-context-processors 用于默认列表。您需要的是以下内容:

 TEMPLATE_CONTEXT_PROCESSORS = (
     "django.contrib.auth.context_processors.auth",
     "django.core.context_processors.debug",
     "django.core.context_processors.i18n",
     "django.core.context_processors.media",
     "django.core.context_processors.static",
     "django.contrib.messages.context_processors.messages",
     "allauth.context_processors.allauth",
     "allauth.account.context_processors.account",
     )

There's a default value for TEMPLATE_CONTEXT_PROCESSORS and you're overriding that one. So now the default ones are missing. And one of them is "django.core.context_processors.static", which is why Django can't find your static files.

See https://docs.djangoproject.com/en/1.3/ref/settings/#template-context-processors for the default list. What you need is the following:

 TEMPLATE_CONTEXT_PROCESSORS = (
     "django.contrib.auth.context_processors.auth",
     "django.core.context_processors.debug",
     "django.core.context_processors.i18n",
     "django.core.context_processors.media",
     "django.core.context_processors.static",
     "django.contrib.messages.context_processors.messages",
     "allauth.context_processors.allauth",
     "allauth.account.context_processors.account",
     )
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文