【代码】Django学习笔记
程序员文章站
2022-06-24 14:37:17
一些设置setting.py 运行项目内应用测试模块tests.py,报错 处理如下: ......
一些设置setting.py
debug = true allowed_hosts = ['*'] databases = { 'default': { 'engine': 'django.db.backends.mysql', 'name': "webdb", 'user': 'root', 'password': '123456', 'host': '127.0.0.1', 'port': '3306', 'conn_max_age': 60*10, } } static_url = '/static/' # static_root = os.path.join(base_dir, 'static/').replace("\\","/") staticfiles_dirs = ( os.path.join(base_dir, "static/").replace("\\", "/"), )
运行项目内应用测试模块tests.py,报错
requested setting default_index_tablespace, but settings are not configured
处理如下:
from django.test import testcase # create your tests here. import os import django os.environ.setdefault('django_settings_module', 'your project.settings') django.setup() # 模型类的导入必须在django启动初始化配置以后进行 from index.models import author author.objects.create(name="小明", age=20, email="110@gmail.com")