pycharm打开django项目
1、file-open,用pycharm加载django项目
2、打开后,点击setting配置环境
file --setting -- Python Interpreter -- 配置python解析器
3、找到django项目的manage.py文件,运行manage.py文件
4、点开配置,parameters: runserver
4、再次启动django项目,报错:
1)TypeError: argument of type ‘WindowsPath’ is not iterable
解决方案:
项目的setitng--DATABASES 的代码 'NAME': BASE_DIR / 'db.sqlite3': 该成 'NAME': str( BASE_DIR / 'db.sqlite3')
改成:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
2)django.core.exceptions.ImproperlyConfigured: WSGI application 'Api_project.wsgi.application' could not be loaded; Error importing module.
解决方案:
查看setting文件有提醒
将该代码块注释掉,且csrf也需注释掉,注释后的代码运行正常
3)创建的项目,提示AttributeError:module'xxx.admin'has no attribute'site'
疑问点:网上查询说是django是2.2的版本,admin应该也是2.的版本,版本不对,需要换成xadmin的版本,但是本地运行其他djgango项目,可以正常运行,故把新建的项目删除,重新创建
解放方案:删除新创建的项目,重新创建,运行正常未报错
5、执行命令
1)python manage.py makemigrations
2)python manage.py migrate
6、启动项目,并打开后台地址
访问地址:http://127.0.0.1:8000/,别人访问:http:// 你电脑的ip地址:8000/,登陆的用户及密码:admin/admin
后台管理地址:http://127.0.0.1:8000/admin