Note that there are some explanatory texts on larger screens.

plurals
  1. POGET shows 304 in django and test fails when entries are listed
    text
    copied!<p>in my django app,I am using a css file and some images for my web pages.I have defined the media_root and media_url as</p> <p>in settings.py</p> <pre><code>MEDIA_ROOT = '/home/me/dev/python/django/myproject/mysite/media/' MEDIA_URL = '/site_media/myapp/' ADMIN_MEDIA_PREFIX = '/media/' TEMPLATE_DIRS = ( '/home/me/dev/python/django/myproject/mysite/myapp/myapptemplates', ) </code></pre> <p>The media folder contains</p> <pre><code>myapp/css and myapp/img folders </code></pre> <p>full path of base.html is </p> <pre><code>/home/me/dev/python/django/myproject/mysite/myapp/myapptemplates/myapp/base.html </code></pre> <p>In the above base.html,I am putting the css and images as</p> <pre><code>&lt;head&gt; &lt;title&gt;myapp&lt;/title&gt; &lt;LINK REL=StyleSheet HREF="{{MEDIA_URL}}css/mystyle.css" TYPE="text/css" MEDIA="screen, print"/&gt; &lt;link rel="shortcut icon" href="{{ MEDIA_URL }}img/my-icon.ico"/&gt; &lt;div id="header"&gt; &lt;img class="centerpage" src="{{ MEDIA_URL }}img/mypic.gif" alt="MY WEB APP PIC"&gt; &lt;/div&gt; </code></pre> <p>When I am trying to list all entries I created in my app,everything shows up properly.But I see 304 response code for GET on the css and images. (I am using django1.1.1 so, I have not used any csrf_token in the templates.) The terminal output by django is</p> <pre><code>[04/Sep/2011 18:15:18] "GET /myapp/entries/ HTTP/1.1" 200 3843 [04/Sep/2011 18:15:18] "GET /site_media/myapp/css/mystyle.css HTTP/1.1" 304 0 [04/Sep/2011 18:15:18] "GET /site_media/myapp/img/mypic.gif HTTP/1.1" 304 0 [04/Sep/2011 18:15:18] "GET /site_media/myapp/img/navigation1.png HTTP/1.1" 304 0 </code></pre> <p>As you can see ,the view returns 200 where as the GET on css and images return 304. The style and images are properly shown on the webpage though.</p> <p>Also,on a maybe related issue, when I test the following view,it fails. </p> <pre><code>@login_required def entries_list(request,template_name,page_title): entries=get_entries_of_user(request.user) dict={'page_title':page_title ,'entries':entries} req_context=RequestContext(request,dict) return render_to_response(template,req_context) class BaseTestCase(TestCase): def setUp(self): super(BaseTestCase,self).setUp() self.client.login(username='me',password='me') class EntryTest(BaseTestCase): fixtures=['entries.json'] def test_entries_list_view(self): print 'reverse=',reverse('myapp_entry_list') response=self.client.get(reverse('myapp_entry_list')) status_code=response.status_code print 'st code=',status_code entries=get_context_variable(response,'entries') self.assertEqual(200,status_code) def get_context_variable(response,name): print 'response_context=',response.context return response.context[name] </code></pre> <p>The print on status code here gives</p> <pre><code>st code= 302 </code></pre> <p>The print on response.context prints 'None' and a type error is raised when response.context['entries'] is tried</p> <pre><code>in get_context_variable return response.context[name] TypeError: 'NoneType' object is unsubscriptable </code></pre> <p>I couldn't figure out why this happens.Can someone help me?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload