[英]How should I change TEMPLATE_CONTEXT_PROCESSORS in Django?
I'm trying to use the Django Social Auth
application to handle logins to my site from a variety of social media sites. 我正在尝试使用
Django Social Auth
应用程序来处理从各种社交媒体网站登录我的网站。
When working through the example code here , the example uses the following settings for TEMPLATE_CONTEXT_PROCESSORS
: 在此处处理示例代码时,该示例对
TEMPLATE_CONTEXT_PROCESSORS
使用以下设置:
TEMPLATE_CONTEXT_PROCESSORS = (
'django.core.context_processors.debug',
'django.core.context_processors.i18n',
'django.core.context_processors.media',
'django.contrib.messages.context_processors.messages',
'social_auth.context_processors.social_auth_by_type_backends',
'django.contrib.auth.context_processors.auth',
)
However, if I use these settings my static media url is ignored (css/js/images are not available), and I think it is overwriting some other context settings. 但是,如果我使用这些设置,我的静态媒体网址将被忽略(css / js / images不可用),我认为它会覆盖其他一些上下文设置。 How can I check if there are more context settings that I should be including?
如何检查是否有更多上下文设置应包括在内?
I think you need to add django.core.context_processors.static
to your list of context processors. 我认为你需要将
django.core.context_processors.static
添加到上下文处理器列表中。
Then maybe have a quick read through the docs on serving static files - The process varies depending on your setup. 那么,也许有通过快速阅读的文档上服务静态文件-的过程取决于您的设置。
It's difficult to say what else you might need in there, I think you've got everything that django drops in there as default (when you run python django-admin.py startapp
). 很难说你在那里还需要什么,我认为你已经拥有了django默认放在那里的一切(当你运行
python django-admin.py startapp
)。 Glancing at one of the current projects I'm working on, I've got django.core.context_processors.request
for passing the request object into the template and one custom context_processor, but obviously what you add is subject to your specific requirements. 浏览我正在处理的当前项目之一,我有
django.core.context_processors.request
将请求对象传递给模板和一个自定义context_processor,但显然你添加的内容取决于你的具体要求。
Have you set your STATICFILES_DIRS
? 你有没有设置
STATICFILES_DIRS
? Also, you should add the django.core.context_processors.static
to your TEMPLATE_CONTEXT_PROCESSORS
and address your static files using the STATIC_URL . 此外,您应该将
django.core.context_processors.static
添加到TEMPLATE_CONTEXT_PROCESSORS
并使用STATIC_URL寻址静态文件。
Also the docs on static files are generally a good read. 静态文件的文档通常也是一个很好的阅读。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.