我已将django-allauth纳入我的网站.它工作但帐户页面上没有样式,虽然index.html扩展了'base.html',但也呈现了普通样式.我有这样的项目结构:
root -myproject -myapp -templates/ base.html index.html .... --/accounts/ login.html logout.html ..... -static/ --admin/ ---css ---js ---img --static/ ---css ---js -media
我的settings.py路径:
TEMPLATE_DIRS = (os.path.join(BASE_DIR,"templates"),) STATICFILES_DIRS = (os.path.join(BASE_DIR,"static"), ) STATIC_URL = '/static/' STATIC_ROOT = os.path.join(BASE_DIR, "static", "admin") MEDIA_URL = '/media/' MEDIA_ROOT = os.path.join(BASE_DIR, 'static', 'media')
base.html文件:
{% load staticfiles %}Title
{% block head_title %} {% endblock %} {% block main_content %} {% endblock main_content %} {% block content %} {% endblock %} {% block step1 %} {% endblock %} {% block step2 %} {% endblock %}
的login.html:
{% extends 'base.html' %} {% load crispy_forms_tags %} {% load i18n %} {% load account socialaccount %} {% block head_title %}{% trans "Sign In" %}{% endblock %} {% block content %}{% endblock %}{% trans "login" %}
{% get_providers as socialaccount_providers %} {% if socialaccount_providers %}{% blocktrans with site.name as site_name %}Please sign in with one of your existing third party accounts. Or, sign up for a {{ site_name }} account and sign in below:{% endblocktrans %}
{% include "socialaccount/snippets/login_extra.html" %} {% else %}
{% trans 'or' %}{% blocktrans %}If you have not created an account yet, then please sign up first.{% endblocktrans %}
{% endif %}
我仍然无法弄清楚它是什么奇怪的问题.请帮忙!
您加载静态文件{% load staticfiles %}
但不使用static
模板标记.
替换所有资产链接 {% static 'path/to/file.ext' %}
例如:
替换
../static/static/css/sticky-footer-navbar.css
用这个:( 如果你的文件是全局静态文件)
{% static 'app_name/css/sticky-footer-navbar.css' %}
用这个:( 如果你的文件是app静态文件)
{% static 'app_name/css/sticky-footer-navbar.css' %}
我建议你仔细阅读Django文档:管理静态文件