django注册模板 [英] django registration template

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

问题描述

我已经做了两个模板(更改passwd,更改passwd完成)。
而且,我试图改变密码。那么,密码已更改。
但是,没有显示成功页面。只能重新加载password_change页面。
我不知道是什么问题?



另外,我不知道注册文件夹在哪里。
云你帮忙吗?
谢谢。

  url(r'^ accounts / chpasswd /?','django.contrib.auth view.password_change',{'template_name':'password_change.html'}),
url(r'^ accounts / chpasswd / done /?','django.contrib.auth.views.password_change_done',{' template_name':'password_change_done.html'}),


解决方案

当您更改密码时,您正在使用一个函数,这很可能在应用程序的views.py文件中。当这个函数结束时,最有可能返回一些数据,最常见的是返回模板。



这里有一个例子:

  return render_to_response('myapplication / frontend.html',{'profile':profile_obj},
context_instance = RequestContext(request))

在这种情况下,它将返回变量值 profile_obj 到模板 frontend.html ,这可能在 /myproject/myapp/templates/myapp/frontpage.html 。之后,您可以通过在模板文件中调用 {{profile.instance}} 来访问该对象的实例。



有关此功能的更多信息可以在这里找到



现在, urls.py 文件是使用的文件用于将请求转发到所需的应用程序。
示例:

  url(r'^ accounts / chpasswd /?',
'django.contrib .auth.views.password_change',
{'template_name':'password_change.html'}),
url(r'^ accounts / chpasswd / done /?',
'django。 contrib.auth.views.password_change',
{'template_name':'password_change_done.html'}),

这意味着以下(给你的网站在www.mysite.com):



当一个打开 www.mysite .com / accounts / chpasswd / ,从 django.contrib.auth password_change $ c> module,如果该函数有效(返回某种值),则返回一个名为 password_change.html



django.contrib.auth模块用于这样的东西:登录和注销,密码功能等。



现在,您应该注意两件事:



1)您的模板必须位于django将寻找他们,所以在settings.py中查看 TEMPLATE_DIRS 设置。



2)我相信我不是100%肯定)Django已经有这样一个模板,预定义。如果您具有与Django默认模板之一相同的模板名称,请确保您的应用程序在 django.contrib.admin INSTALLED_APPS ,否则会显示一个django模板(与django admin共享相同的设计)。



========= ========================



自编辑问题以来编辑



尝试更改urls.py中的顺序,如下所示:

  url r'^ accounts / chpasswd / done /?',
'django.contrib.auth.views.password_change_done',
{'template_name':'password_change_done.html'}),

url(r'^ accounts / chpasswd /?',
'django.contrib.auth.views.password_change',
{'template_name':'password_change.html'}),


I have made two templates(change passwd, change passwd done). And, I tried to changepassword. then, Password changed. But, Success page is not shown.only password_change page reloaded. I dont know What is problems?

One more, I don't know where is registration folder. Cloud you help it? Thank you.

url(r'^accounts/chpasswd/?', 'django.contrib.auth.views.password_change', {'template_name':'password_change.html'}),
url(r'^accounts/chpasswd/done/?', 'django.contrib.auth.views.password_change_done', {'template_name':'password_change_done.html'}),

解决方案

When you're changing password, you're using a function, that's most probably in your application's views.py file. When that function is at the end, it's most probably going to return some data, and it most often returns it to the template.

Here's an example:

return render_to_response('myapplication/frontend.html', {'profile': profile_obj},
        context_instance=RequestContext(request))

In this case, it's going to return the value of variable profile_obj to the template frontend.html, which is probably in /myproject/myapp/templates/myapp/frontpage.html. After that, you can access that object's instances by invoking {{ profile.instance }} from within your template file.

More about this function can be found here.

Now, urls.py file is the file that's used for forwarding requests to desired application. Example:

url(r'^accounts/chpasswd/?',
    'django.contrib.auth.views.password_change',
    {'template_name':'password_change.html'}), 
url(r'^accounts/chpasswd/done/?', 
    'django.contrib.auth.views.password_change', 
    {'template_name':'password_change_done.html'}),

And this means following(given your website is at www.mysite.com):

When a one opens www.mysite.com/accounts/chpasswd/, run function password_change from a view of django.contrib.auth module, and if that function is fruitful(returns a value of some kind), let it return a value to a template called password_change.html

django.contrib.auth module is used for stuff like that: logging in and out, password functions and so.

Now, you should be aware of 2 things:

1) your templates must be in a place where django will be looking for them, so check TEMPLATE_DIRS setting in settings.py.

2) I believe(but am not 100% sure) that Django already has such a template, predefined. In case you have the same template name as one of Django's default templates, make sure that your app comes before django.contrib.admin in INSTALLED_APPS, or else you'll be shown a django template(shares the same design as django admin).

===================================

EDIT since question was edited, too

Try changing order in urls.py, like so:

url(r'^accounts/chpasswd/done/?', 
    'django.contrib.auth.views.password_change_done', 
    {'template_name':'password_change_done.html'}),

url(r'^accounts/chpasswd/?', 
    'django.contrib.auth.views.password_change', 
    {'template_name':'password_change.html'}),

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

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