其他问题的答案给人的印象是,这实际上是非常容易的:
然而,我根本无法让它发挥作用。
从示例应用程序设置中我可以看到django-allauth应该期望它的模板位于account、openid和socialaccount目录中。但是当我将模板放在TEMPLATE_DIR/account/signup.html时,它没有加载,signup视图显示了与django-allauth捆绑的模板。我错过了什么?
发布于 2013-09-15 11:08:28
最后,我不得不在django之前加载我的应用程序。在settings.py中
INSTALLED_APPS = (
...
'myapp',
'allauth',
'allauth.account'
)这个解决方案与示例应用程序中的内容相反,但我无法以其他方式解决它。
发布于 2015-07-08 02:18:59
Adding a template directory for allauth in template dirs会做到这一点的。在Django 1.8中,可以通过编辑模板dir设置TEMPLATES来完成his,如下所示。
TEMPLATES = [
...
'DIRS': [
os.path.join(BASE_DIR, 'templates'),
os.path.join(BASE_DIR, 'templates', 'allauth'),
],
]我认为下面的代码将适用于django的其他版本
TEMPLATE_DIRS = [
os.path.join(BASE_DIR, 'templates'),
os.path.join(BASE_DIR, 'templates', 'allauth'),
]发布于 2017-02-05 13:20:03
直到今天--我们现在用的是django--1.10.5--django-我们现在用的是django-1.10.5-django-在这方面,django尽管在DIRS中设置了TEMPLATES,但Django似乎确实查看了列出的第一个应用程序的模板目录。我提供的答案只是为了帮助您实现Adam的答案,帮助您处理反向urls (在处理这些错误之前,我得到了错误)。
在您的urls.py文件中放置:
from allauth.account.views import SignupView, LoginView, PasswordResetView
class MySignupView(SignupView):
template_name = 'signup.html'
class MyLoginView(LoginView):
template_name = 'login.html'
class MyPasswordResetView(PasswordResetView):
template_name = 'password_reset.html'
urlpatterns = [
url(r'^accounts/login', MyLoginView.as_view(), name='account_login'),
url(r'^accounts/signup', MySignupView.as_view(), name='account_signup'),
url(r'^accounts/password_reset', MyPasswordResetView.as_view(), name='account_reset_password'),
]目前,views.py文件是这里文件,因此您可以将上面的内容扩展到其他模板。
我必须补充一点,您仍然需要在TEMPLATES中使用,类似于:
'DIRS': [
os.path.join(PROJECT_ROOT, 'templates', 'bootstrap', 'allauth', 'account'),
],在这个例子中,如果模板是在/templates/bootstrap/allauth/account中的,我就是这样做的。和:
PROJECT_ROOT = os.path.normpath(os.path.dirname(os.path.abspath(__file__)))编辑..。适当的方法:
好的,上面的工作,在一定程度上,它是好的,它直接设置模板,你想要什么。但是一旦你包含了社交应用程序,你就会开始得到反向url错误,比如dropbox_login,你还没有为它提供一个命名视图。
在阅读了发问者发现的Burhan在另一个堆栈溢出线程上的评论之后,我最终发现了以下一些作品:
'DIRS': [
os.path.join(PROJECT_ROOT, 'templates', 'example'),
]在我的例子中,这会在开发服务器上产生/home/mike/example/example/templates/example,因为我是从git clone git://github.com/pennersr/django-allauth.git运行example应用程序的。
我从提供的示例DIRS模板中复制了整个子目录account和socialaccount。这与example的目录结构完全相反,因为它来自github,也与example的settings.py文件中的注释完全相反。
您离开urls.py就像在example应用程序中一样,只需:
url(r'^accounts/', include('allauth.urls')), https://stackoverflow.com/questions/18791136
复制相似问题