django.test.client 使用随记

时间:2022-12-12 22:46:51
import os,sys,django;

sys.path.append("\\path\\to\\mysite")#ATTETION!,Err: "unable to configure filter 'special'django.core.exceptions.ImproperlyConfigured"

os.environ["DJANGO_SETTINGS_MODULE"]="mysite.settings"#Attention!Err: 'no handlers could be found for logger "django.request"'

django.setup()#ATTETION!,raise django.core.exceptions.ImproperlyConfigured

from django.test.utils import setup_test_environment

from django.test.client import Client

from django.core.urlresolvers import reverse

setup_test_environment()

client = Client()

response = client.get('/')