Re: View not working / how can I test it in the shell?
Thanks Kelvin
Dtb/Gby
On Sun, Oct 13, 2013 at 12:34 AM, Kelvin Wong <wongo888@gmail.com> wrote:
You need to understand what ALLOWED_HOSTS does if you want to ever deploy your app. Please read it.Check your settings in the shell>>> from django.conf import settings as s>>> s.DEBUGTrue>>> s.ALLOWED_HOSTS['.example.com', '192.168.0.2']If your DEBUG is False and your ALLOWED_HOSTS is an empty list [] then you will not get far. You will get a "SuspiciousOperation: Invalid HTTP_HOST header (you may need to set ALLOWED_HOSTS)" message.You can try putting something like this into the template (pretty much straight from the Django blog example), and it will tell you nicely when it has nothing matching your query or if your db is empty:{% block featured_posts %}{% if featured_posts_list %}{% for blog_post in featured_posts_list %}<p>{{ blog_post.title }}</p><br>{% endfor %}{% else %}<p>No posts found</p>{% endif %}{% endblock %}You might also want to ensure that your view is rendering the right template and that the template hierarchy is correct (ie. {% extends "my_templates/base.html" %} is at the top of your template and it is correct). If your parent template that you're extending doesn't have a block named 'featured_posts' then it won't display anywhere. You won't see the "No posts found" message nor will you see your list of blogs - nada.If there is an exception in the shell, it will print out a trace. This is an actual Dj1.5 trace from a made up exception I planted in the view. You can also put objects like your queryset into the Exception message and see if your set is producing what you think it should be.>>> from django.test import Client>>> c = Client()>>> c.get('/')Internal Server Error: /Traceback (most recent call last):File "/Users/kelvin/.virtualenvs/myproject/lib/python2.7/site-packages/django/core/handlers/base.py", line 115, in get_responseresponse = callback(request, *callback_args, **callback_kwargs)File "/Users/kelvin/.virtualenvs/myproject/lib/python2.7/site-packages/django/views/generic/base.py", line 68, in viewreturn self.dispatch(request, *args, **kwargs)File "/Users/kelvin/.virtualenvs/myproject/lib/python2.7/site-packages/django/views/generic/base.py", line 86, in dispatchreturn handler(request, *args, **kwargs)File "/Users/kelvin/repos/myproject_files/myproject_repo/myproject/firstweb/views.py", line 14, in getraise Exception("Freek out!")Exception: Freek out!
On Friday, October 11, 2013 5:25:54 PM UTC-7, Mario Osorio wrote:From the server; I am getting the page I need but the block where the data from the view in question is supposed to be comes out empty.I am indeed geting the ALLOWED_HOSTS warning, which I don't fully understand and don't know hoe to fix. I do have ALLOWED_HOSTS = ('localhost', '.local') and DEBUG = True as I read in Rod's excellent tutorial, but that did not help.
--To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/997818db-a73c-40d2-9e81-386b533609b6%40googlegroups.com.
You received this message because you are subscribed to a topic in the Google Groups "Django users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/django-users/jLHmh2-Ami0/unsubscribe.
To unsubscribe from this group and all its topics, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAO2PNV42VQXDXYQ3apo3vkpbdNHSnEue9u%3D0BAEo1-J2V4c9Bg%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home