Django報錯解決方法
無法使用Django新建專案:'django-admin.py’不是內部或外部命令
找到site-packages/django/bin(如 D:\Program Files\Anaconda3\Lib\site-packages\django\bin),把這個路徑加入系統環境變數中。
error: unrecognized arguments: getall
原因:django版本和程式碼裡的requirements.txt要求的不符
解決:重灌django制定版本的程式碼
要用 pip 安裝指定版本的 Python 包,只需通過 == 操作符 指定 pip install robotframework==2.8.7 將安裝robotframework 2.8.7 版本。
‘WSGIRequest’ object has no attribute ‘user’
這是Django版本的問題,
1.9之前,中介軟體的key為MIDDLEWARE_CLASSES,
1.9之後,為MIDDLEWARE。
所以在開發環境和其他環境的版本不一致時,要特別小心,會有坑。需要在settings裡面把MIDDLEWARE改為MIDDLEWARE_CLASSES 即可
TypeError at / ‘bool’ object is not callable
使用 Django自帶的 auth 使用者驗證功能,編寫函式,使用 is_authenticated 檢查使用者是否登入報錯
def index(request, pid=None, del_pass=None): if request.user.is_authenticated(): username = request.user.username useremail = request.user.email messages.get_messages(request) template = get_template('index.html') html = template.render(context=locals(), request=request) returnHttpResponse(html)
查詢相關資料,發現 is_authenticated 是屬性而不是方法,我們應該把括號去掉,這樣就沒什麼問題了。
將 if request.user.is_authenticated(): 改為 if request.user.is_authenticated:
錯誤編碼1050
python manage.py migrate myapp --fake # 資料庫表結構同步成功
錯誤編碼1146
1.同步資料庫
專案建起來後,同步資料庫,加入自定義的app
python manage.py syncdb
2.建立初始的遷移指令碼
python manage.py makemigrations appname
3.同步遷移資料庫
python manage.py migrate appname
user.User.basemodel_ptr: (fields.E300) Field defines a relation with model ‘BaseModel’, which is either not installed, or is abstract.