本文介绍了Django在使用django-allauth时无法找到静态文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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"
)

我没有在我的设置文件中有更早的TEMPLATE_CONTEXT_PROCESSORS。有没有我失踪的东西?我应该如何解决这个问题。当我看到DEBUG控制台时,我可以看到它正在尝试将css文件作为

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"

而应该是

"GET /static/css/contact.css"


推荐答案

TEMPLATE_CONTEXT_PROCESSORS有一个默认值,您将覆盖该默认值。所以现在缺少缺省的。其中一个是django.core.context_processors.static,这就是为什么Django找不到你的静态文件。

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",
     )

这篇关于Django在使用django-allauth时无法找到静态文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-26 03:23