django.test.client 使用随记

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('/')
原文地址:https://www.cnblogs.com/xuesu/p/4709595.html