I've deployed my Django project on Heroku. Now when I'm trying to access the admin page url/admin
, I'm getting
AttributeError at /admin
'AnonymousUser' object has no attribute 'first_name'
If I'm running the same code locally, there's no issue with the admin page. It opens fine.
So problem is with this line actually in views.py
/app/exam/views.py in topic_view
Line:59 | fname = request.user.first_name
So my problem is why views.py is being called when I'm trying to open the admin site.
edit:
This is the urls.py file for app 'exam'
from django.urls import path
from . import views
urlpatterns = [
path("", views.index, name="index"),
path("login", views.login_view, name="login"),
path("search", views.search_view, name="search"),
path("logout", views.logout_view, name="logout"),
path("register", views.register_view, name="register"),
path("<str:subject_code>", views.topic_view, name="topics"),
path("instructions/<int:topic_id>", views.instruction_view, name="instructions"),
path("test/<int:topic_id>", views.test_view, name="test"),
path("test/score/<int:topic_id>", views.score_calculator, name="score"),
]
and this is the urls.py for project 'quiz'
from django.contrib import admin
from django.urls import include, path
urlpatterns = [
path("admin/", admin.site.urls),
path("", include("exam.urls")),
]
由于您有 AnonymousUser 错误,这意味着用户未登录,并且由于他/她未登录,因此他/她不能拥有任何属性,例如 username、first_name 等。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.