python - Django test view issue -
python - Django test view issue -
i'm trying test view in django project. can't context view. i'm working in shell. type:
>>> django.test.client import client >>> c = client() >>> c.login(username='test', password='test') true >>> response = c.get(reverse('lista_categorie')) >>> response.status_code 200 >>> response.context['categorie'] traceback (most recent phone call last): file "<console>", line 1, in <module> typeerror: 'nonetype' object has no attribute '__getitem__'
i have variable 'category' give template context, cannot understand why context empty. status code ok, , content corrisponds template. view:
def lista_categorie(request): categorie = categoria.objects.all() homecoming render_to_response('view_categories.html', { 'categorie': categorie, }, context_instance=requestcontext(request))
any ideas?
previous reply wrong. here's solution http://jazstudios.blogspot.com/2011/01/django-testing-views.html, add together line can access context during tests:
>>> django.test.utils.setup_test_environment()
i haven't test myself, test it.
python django testing view get
Comments
Post a Comment