开发者

Pre-filled user info in Django Comments?

开发者 https://www.devze.com 2023-01-30 11:22 出处:网络
The site I\'m building uses the standard user management framewo开发者_如何学Gork and the standard comments framework.

The site I'm building uses the standard user management framewo开发者_如何学Gork and the standard comments framework.

What I'd like to see happen is the comments form rendered with the user's name and email address pre-filled if they are already signed in (or have the fields hidden entirely - kinda like theregister's comments system!).

Easy enough?


If you want to use django-comments with logged-in users, the post_comment does already populate some fields right when being authenticated, you just need to make some tweaks. There are some instructions on how to do that!


If user are signed in, you can use something like this in your view:

 user = request.user
 profile = user.get_profile()
 if request.method == 'POST':
       edit_form = YourForm(data = request.POST, user = user)
       if edit_form.is_valid():
            ...
 else:
       dict = {'email':user.email, 'username':user.username}
       form = YourForm(user = user, data = dict)
       tpl_dict = {'form' : form,}
       return render_to_response('template.html', tpl_dict)

it will fill the form fields 'username' and 'email'


When I'm signed into my django site it automatically loads my username and email address.

0

精彩评论

暂无评论...
验证码 换一张
取 消