覆盖django-allauth中的模板 [英] override templates in django-allauth

查看:76
本文介绍了覆盖django-allauth中的模板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经阅读了所有可以在StackOverflow上找到的解决方案,并通过了allauth文档.仍然不能指向本地模板(在Django项目中为 ),而不是allauth模板(即登录,注册等)

I have read all the possible solutions I can find on StackOverflow and been through the allauth documents. Still not able to point to my local (in my Django project) templates instead of the allauth ones (i.e. login, signup, etc.)

1.将我的应用程序移到settings.py INSTALLED_APPS中的allauth之前,这样看起来:

'users', #my custom user model app
'date_track.apps.DateTrackConfig', # main app

'django.contrib.sites',
'allauth',
'allauth.account',
'allauth.socialaccount',
'allauth.socialaccount.providers.twitter',

]

2.修改了我的项目结构,并将所有身份验证模板(登录,注册等)移到了该位置.

  • 结构现在看起来像这样:

my_project/templates/allauth/在此目录中,我有3个allauth目录:1.帐户2. openid3.socialaccount

my_project/templates/allauth/ inside this dir I have the 3 allauth dirs: 1. account 2. openid 3.socialaccount

在这些目录中,我拥有所有的allauth模板,另外,base.html

And inside these dirs I have all the allauth templates, plus, base.html

3.我已经在settings.py中修改了模板设置",使其看起来像这样:

'DIRS': [os.path.join(BASE_DIR, 'templates'), os.path.join(BASE_DIR, 
'templates', 'allauth','accounts', 'socialaccount')],

但是,每当我访问主页上的链接(该链接继承自项目的base.html)时,它都会直接转到以下模板:site-packages/allauth/templates/account目录.

Yet, whenever I access the link off my home page (which inherits from my project's base.html), it heads right over to the templates in: site-packages/allauth/templates/account directory.

base.html包含指向模板的链接,如下所示:

base.html has the links to the templates as follows:

{% if user.is_authenticated %}
   <li class="nav-item">
     <p><h6>You are Logged in as <I>{{user.username}}</I></h6></p>
  </li>
  <li class="nav-item">
     <a class="nav-link active" href="{% url 'account_email' 
     %}">Email</a>
  </li>
  <li class="nav-item">
     <a class="nav-link" href="{% url 'account_logout' %}">Sign 
     out</a>
  </li>
{% else %}
  <li class="nav-item">
    <a class="nav-link" href="{% url 'account_login' %}">Sign in</a>
 </li>
 <li class="nav-item">
   <a class="nav-link " href="{% url 'account_signup' %}" 
    tabindex="-1">Sign up</a>
 </li>
{% endif %}

我一定在做傻事,但似乎找不到.感谢您的帮助!

I must be doing something silly, but I can't seem to find it. Thanks for the help!

推荐答案

您的模板目录结构是否与此匹配:

Have your template directory structure match this:

# correct
templates\account
templates\openid
templates\socialaccount

您似乎拥有一对多目录:

It looks like you have one to many directories:

# incorrect
templates\allauth\account
templates\alluth\openid
templates\alluth\socialaccount

链接到allauth来源[1]以供参考

Link to the allauth source[1] for reference

[1] https://github.com/pennersr/django-allauth/tree/master/allauth/templates

这篇关于覆盖django-allauth中的模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆