擅长:python、mysql、java
<pre><code>class ProjectTest(TestCase):
def test_login_feature(self):
user = User.objects.create_user(username='joe', password='pass')
self.client.login(username='joe', password='pass')
# client now authenticated and can access
# restricted views.
</code></pre>
<p>所以这就是你要做的。创建一个用户并使用<code>self.client.login</code>您可以在<a href="https://docs.djangoproject.com/en/1.6/topics/testing/tools/#django.test.client.Client.login" rel="nofollow">documentation</a>中阅读有关如何使用它的更多信息</p>