Electronics & Programming

develissimo

Open Source electronics development and programming

  • You are not logged in.
  • Root
  • » Django
  • » testclient cannot find the template [RSS Feed]

#1 Dec. 15, 2010 09:14:37

Kenneth G.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

testclient cannot find the template


hi,

I am trying to write a test of a view with test client. My test is like
this:

class Testgetnum(unittest.TestCase):
def setUp(self):
self.client = Client()
def testgetnum(self):
response = self.client.post('/success/',{'id':1})
self.assertEqual(response.status_code, 200)

but the test crashes since it cannot find the template mentioned in the
view. But the template is there in the correct directory pointed to by
settings. The error traceback is:

Traceback (most recent call
last):

File "/home/lawgon/addition/../addition/addnums/tests.py", line 38, in
testgetnum
response =
self.client.post('/success/',{'id':1})

File "/usr/lib/python2.6/site-packages/django/test/client.py", line
444, in post
response = super(Client, self).post(path, data=data,
content_type=content_type, **extra)
File "/usr/lib/python2.6/site-packages/django/test/client.py", line
245, in post
return
self.request(**r)

File "/usr/lib/python2.6/site-packages/django/core/handlers/base.py",
line 139, in get_response
response = callback(request,
**param_dict)

File "/usr/lib/python2.6/site-packages/django/utils/decorators.py",
line 89, in _wrapped_view
response = view_func(request, *args,
**kwargs)
File "/usr/lib/python2.6/site-packages/django/views/defaults.py", line
18, in page_not_found
t = loader.get_template(template_name) # You need to create a
404.html template.
File "/usr/lib/python2.6/site-packages/django/template/loader.py",
line 157, in get_template
template, origin =
find_template(template_name)

File "/usr/lib/python2.6/site-packages/django/template/loader.py",
line 138, in find_template
raise
TemplateDoesNotExist(name)

TemplateDoesNotExist: 404.html
--
regards
Kenneth Gonsalves

--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

#2 Dec. 15, 2010 11:49:39

Piotr Z.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

testclient cannot find the template


Hi Kenneth,

It looks like the test can't find the /success/ URL
and then tries to display a 404 error, but there is o 404.html template

Do you have 404.html template created?

zalun

On 10-12-15 01:13, Kenneth Gonsalves wrote:hi,

I am trying to write a test of a view with test client. My test is like
this:

class Testgetnum(unittest.TestCase):
def setUp(self):
self.client = Client()
def testgetnum(self):
response = self.client.post('/success/',{'id':1})
self.assertEqual(response.status_code, 200)

but the test crashes since it cannot find the template mentioned in the
view. But the template is there in the correct directory pointed to by
settings. The error traceback is:

Traceback (most recent call
last):
File "/home/lawgon/addition/../addition/addnums/tests.py", line 38, in
testgetnum
response =
self.client.post('/success/',{'id':1})
File "/usr/lib/python2.6/site-packages/django/test/client.py", line
444, in post
response = super(Client, self).post(path, data=data,
content_type=content_type, **extra)
File "/usr/lib/python2.6/site-packages/django/test/client.py", line
245, in post
return
self.request(**r)
File "/usr/lib/python2.6/site-packages/django/core/handlers/base.py",
line 139, in get_response
response = callback(request,
**param_dict)
File "/usr/lib/python2.6/site-packages/django/utils/decorators.py",
line 89, in _wrapped_view
response = view_func(request, *args,
**kwargs)
File "/usr/lib/python2.6/site-packages/django/views/defaults.py", line
18, in page_not_found
t = loader.get_template(template_name) # You need to create a
404.html template.
File "/usr/lib/python2.6/site-packages/django/template/loader.py",
line 157, in get_template
template, origin =
find_template(template_name)
File "/usr/lib/python2.6/site-packages/django/template/loader.py",
line 138, in find_template
raise
TemplateDoesNotExist(name)
TemplateDoesNotExist: 404.html--
bloghttp://piotr.zalewa.infojobshttp://webdev.zalewa.infotwithttp://twitter.com/zalunfacehttp://www.facebook.com/zaloon--
You received this message because you are subscribed to the Google Groups "Django
users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

#3 Dec. 15, 2010 11:53:42

Kenneth G.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

testclient cannot find the template


On Wed, 2010-12-15 at 03:44 -0800, Piotr Zalewa wrote:
> It looks like the test can't find the /success/ URL
> and then tries to display a 404 error, but there is o 404.html
> template
>
> Do you have 404.html template created?

no 404 template - but why can it not find the /success/ url? Do I need
to import urls.py also?
--
regards
Kenneth Gonsalves

--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

#4 Dec. 15, 2010 12:04:25

Kenneth G.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

testclient cannot find the template


On Wed, 2010-12-15 at 17:23 +0530, Kenneth Gonsalves wrote:
> On Wed, 2010-12-15 at 03:44 -0800, Piotr Zalewa wrote:
> > It looks like the test can't find the /success/ URL
> > and then tries to display a 404 error, but there is o 404.html
> > template
> >
> > Do you have 404.html template created?
>
> no 404 template - but why can it not find the /success/ url? Do I need
> to import urls.py also?

solved - the url was wrong
--
regards
Kenneth Gonsalves

--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

#5 Dec. 15, 2010 12:04:32

Piotr Z.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

testclient cannot find the template


This should work, is /success working in dev server?

zalun

On 10-12-15 03:53, Kenneth Gonsalves wrote:On Wed, 2010-12-15 at 03:44 -0800, Piotr Zalewa wrote:It looks like the test can't find the /success/ URL
and then tries to display a 404 error, but there is o 404.html
template

Do you have 404.html template created?no 404 template - but why can it not find the /success/ url? Do I need
to import urls.py also?--
bloghttp://piotr.zalewa.infojobshttp://webdev.zalewa.infotwithttp://twitter.com/zalunfacehttp://www.facebook.com/zaloon--
You received this message because you are subscribed to the Google Groups "Django
users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

Board footer

Moderator control

Enjoy the 14th of December
PoweredBy

The Forums are managed by develissimo stuff members, if you find any issues or misplaced content please help us to fix it. Thank you! Tell us via Contact Options
Leave a Message
Welcome to Develissimo Live Support