AnonymousUser problem in Django, Feedback App
user = models.ForeignKey(User,)
I have a user开发者_高级运维 foreignkey in models.py
if request.user.is_authenticated():
feedback.user = request.user
else:
feedback.user = 'something'
In views.py, If user logged in feedback.user area, write username else write something there. How can I do this in Django.
I was trying to django-feedback and it was like just
feedback.user = request.user
Like this, it was giving the error below.
Cannot assign "<django.contrib.auth.models.AnonymousUser
object at 0x2dbcf50>": "Feedback.user" must be a "User" instance
I am working on localhost. Any idea?
Either require the user to be logged in for the view, or handle it yourself and assign None.
精彩评论