Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
584 views
in Technique[技术] by (71.8m points)

passwords - django registration template

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'}),
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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'}),

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...