URLでテストを実行すると、200ではなく302が返されます。リダイレクトテスターでプロダクションで同じURLをテストすると、200が返されます。Django Test client.get()は200の代わりに302コードを返します
tests.py
def test_detail(self):
response = self.client.get('/p/myproduct-detail.html')
self.assertEqual(response.status_code, 200)
urls.py
url(r'^p/(?P<slug>[-\w\d]+).html$', main.views.product_detail,
name='product-detail'),
views.py
def product_detail(request, slug):
stuff...
return render(request, 'product-detail.html', {})
私はclient.get()
にfollow=True
を追加する場合は、予想通り、私は200のコードを受け取ります。
ブラウザでURLを開くと、最後に表示されるURLは/p/myproduct-detail.htmlまたは/p/myproduct-detail.html/ですか? – Kostas
@Kostas /p/myproduct-detail.html – KingFu