[Fixed]-ValueError at /new_topic/ Cannot assign "<SimpleLazyObject: <django……>": "Topic.owner" must be a "User" instance

1👍

Setting new_topic.owner = request.user should be fine if the user is logged in. However if the user is not logged in, then trying to assign an anonymous user would cause problems.

You can prevent this by using the login_required decorator, so that only logged-in users can access the view.

@login_required
def new_topic(request):
    ...

Leave a comment