在我切換抽象用戶后,我在 dev 上的登錄/管理頁面無法使用 Debug = True 和 python manage.py runserver 進行簽名。
盡管沒有任何問題,但它適用于產品。
登錄開發時,我得到
Please enter a correct username and password. Note that both fields may be case-sensitive.
我還洗掉了我的 sqlite 資料庫并在其上使用了 makemigrations。
我想要做的就是向用戶添加一個欄位,以便他們可以上傳檔案。
模型.py
from django.db import models
from django.contrib.auth.models import AbstractUser
class Profile(AbstractUser):
""" bio = models.TextField(max_length=500, blank=True)
phone_number = models.CharField(max_length=12, blank=True)
birth_date = models.DateField(null=True, blank=True) """
avatar = models.ImageField(default='default.png', upload_to='users/', null=True, blank=True)
管理檔案
from django.contrib import admin
from django.contrib.auth.admin import UserAdmin
from .models import Profile
class CustomUserAdmin(UserAdmin):
pass
admin.site.register(Profile, CustomUserAdmin)
設定.py
# Extends default user with additional fields
AUTH_USER_MODEL = 'pages.Profile'
當我使用遷移時
(portfolio) PS C:\Users\arund\Desktop\Code\Django\portfolio-project> python manage.py showmigrations
admin
[X] 0001_initial
[X] 0002_logentry_remove_auto_add
[X] 0003_logentry_add_action_flag_choices
auth
[X] 0001_initial
[X] 0002_alter_permission_name_max_length
[X] 0003_alter_user_email_max_length
[X] 0004_alter_user_username_opts
[X] 0005_alter_user_last_login_null
[X] 0006_require_contenttypes_0002
[X] 0007_alter_validators_add_error_messages
[X] 0008_alter_user_username_max_length
[X] 0009_alter_user_last_name_max_length
[X] 0010_alter_group_name_max_length
[X] 0011_update_proxy_permissions
[X] 0012_alter_user_first_name_max_length
contenttypes
[X] 0001_initial
[X] 0002_remove_content_type_name
pages
[X] 0001_initial
sessions
[X] 0001_initial
嘗試使用 Debug = True 登錄的回溯
登錄開發時,我得到
(portfolio) PS C:\Users\arund\Desktop\Code\Django\portfolio-project> python manage.py runserver
Watching for file changes with StatReloader
Performing system checks...
System check identified no issues (0 silenced).
December 18, 2021 - 13:11:34
Django version 3.2.9, using settings 'portfolio.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CTRL-BREAK.
[18/Dec/2021 13:11:46] "GET / HTTP/1.1" 200 753
Not Found: /favicon.ico
[18/Dec/2021 13:11:47] "GET /favicon.ico HTTP/1.1" 404 2716
[18/Dec/2021 13:11:49] "GET /accounts/login/ HTTP/1.1" 200 1215
[18/Dec/2021 13:11:50] "POST /accounts/login/ HTTP/1.1" 200 1369
[18/Dec/2021 13:12:03] "POST /accounts/login/ HTTP/1.1" 200 1368
[18/Dec/2021 13:12:22] "POST /accounts/login/ HTTP/1.1" 200 1368
[18/Dec/2021 13:12:30] "POST /accounts/login/ HTTP/1.1" 200 1368
[18/Dec/2021 13:12:36] "POST /accounts/login/ HTTP/1.1" 200 1368
[18/Dec/2021 13:12:43] "POST /accounts/login/ HTTP/1.1" 200 1368
[18/Dec/2021 13:13:15] "POST /accounts/login/ HTTP/1.1" 200 1368
uj5u.com熱心網友回復:
python manage.py createsuperuser洗掉資料庫后你運行了嗎?
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/385924.html
