开发者

authenticated commenting in Django

开发者 https://www.devze.com 2023-03-02 02:11 出处:网络
I\'d like to implement authenticated commenting in Django. I\'ve searched the net and found a few answers, includi开发者_如何转开发ng a few here on SO, but they are mostly from 2008 and 2009, on Djang

I'd like to implement authenticated commenting in Django. I've searched the net and found a few answers, includi开发者_如何转开发ng a few here on SO, but they are mostly from 2008 and 2009, on Django 1.1 or so. I'm currently on Django 1.3. I'm wondering if there's an elegant solution in Django 1.3.

I can hide the comment form in the template if user is not authenticated, that much I know.

How do I deal with the view? I read a few articles that show how to deal with the view, including pre-populating the form and using some try-except blocks to make sure the incoming user data is correct, but they seem pretty hacky. Is there a better way now in Django 1.3?

Btw I implement a very simple registration system in my app. I don't ask for first name, last name, etc etc. Just a username, an email (even a fake one), and a password. So my Users will have only username, email, and password in the database.

Thanks!


For anyone that's wondering, it turns out that in Django 1.3 you need not worry about the User model fields when submitting a form. In your form, simply have form.comment and the hidden fields object_pk, content_type, and timestamp, and if the user is logged in already the other fields like first name, etc. will be taken care of automatically.

0

精彩评论

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