社区所有版块导航
Python
python开源   Django   Python   DjangoApp   pycharm  
DATA
docker   Elasticsearch  
aigc
aigc   chatgpt  
WEB开发
linux   MongoDB   Redis   DATABASE   NGINX   其他Web框架   web工具   zookeeper   tornado   NoSql   Bootstrap   js   peewee   Git   bottle   IE   MQ   Jquery  
机器学习
机器学习算法  
Python88.com
反馈   公告   社区推广  
产品
短视频  
印度
印度  
Py学习  »  问与答

pycharm 社区版 无法导入包是什么情况?哪位进来帮我看看

简单地飞 • 4 年前 • 595 次点击  

Python3.7.4 Pycharm 2019 社区版 Django框架2.2.5

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

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/46863
 
595 次点击