BUG資訊:
D:\Programming\Python37\python.exe "D:/Programming Project/Pycharm Community Project/my/mysite/login/views.py"
Traceback (most recent call last):
File "D:/Programming Project/Pycharm Community Project/my/mysite/login/views.py", line 3, in <module>
from . import models
ImportError: cannot import name 'models' from '__main__' (D:/Programming Project/Pycharm Community Project/my/mysite/login/views.py)
Process finished with exit code 1
源代碼:
from django.shortcuts import render
from django.shortcuts import redirect
from . import models
# Create your views here.
def index(request):
pass
return render(request, 'login/index.html')
def login(request):
if request.method == "POST":
username = request.POST.get('username')
password = request.POST.get('password')
message = '請檢查填寫內容'
if username.strip() and password: # 確保用戶名和密碼都不為空
# 用戶名字符合法性驗證
# 密碼長度驗證
# 更多的其它驗證.....
try:
user = models.User.objects.get(name=username)
except:
message = '用戶不存在'
return render(request, 'login/login.html',{'message':message})
if user.password == password:
print(username, password)
return redirect('/index/')
else:
message = '密碼不正確'
return render(request, 'login/login.html', {'message': message})
else:
return render(request, 'login/login.html', {'message': message})
return render(request, 'login/login.html')
def register(request):
pass
return render(request, 'login/register.html')
def logout(request):
pass
return redirect("/login/")
Debug提示資訊:
D:\Programming\Python37\python.exe "D:\Programming\PyCharm Community Edition 2019.2.3\helpers\pydev\pydevd.py" --multiproc --qt-support=auto --client 127.0.0.1 --port 51913 --file "D:/Programming Project/Pycharm Community Project/my/mysite/login/views.py"
pydev debugger: process 3836 is connecting
Connected to pydev debugger (build 192.6817.19)
Traceback (most recent call last):
File "D:\Programming\PyCharm Community Edition 2019.2.3\helpers\pydev\pydevd.py", line 2073, in <module>
main()
File "D:\Programming\PyCharm Community Edition 2019.2.3\helpers\pydev\pydevd.py", line 2067, in main
globals = debugger.run(setup['file'], None, None, is_module)
File "D:\Programming\PyCharm Community Edition 2019.2.3\helpers\pydev\pydevd.py", line 1418, in run
return self._exec(is_module, entry_point_fn, module_name, file, globals, locals)
File "D:\Programming\PyCharm Community Edition 2019.2.3\helpers\pydev\pydevd.py", line 1425, in _exec
pydev_imports.execfile(file, globals, locals) # execute the script
File "D:\Programming\PyCharm Community Edition 2019.2.3\helpers\pydev\_pydev_imps\_pydev_execfile.py", line 18, in execfile
exec(compile(contents+"\n", file, 'exec'), glob, loc)
File "D:/Programming Project/Pycharm Community Project/my/mysite/login/views.py", line 3, in <module>
from . import models
ImportError: cannot import name 'models' from '__main__' (D:/Programming Project/Pycharm Community Project/my/mysite/login/views.py)
Process finished with exit code 1
uj5u.com熱心網友回復:
upupup
upupup
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/153155.html
