django registration template

守給你的承諾、 提交于 2019-12-12 02:53:49

问题


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

回答1:


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


来源:https://stackoverflow.com/questions/8997923/django-registration-template

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!