一些设置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")