一些設置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="[email protected]")