View loaded twice / Database entry saved twice

38 views
Skip to first unread message

James Verran

unread,
Aug 21, 2012, 7:07:04 PM8/21/12
to django...@googlegroups.com
Hi there, I'm trying to capture all url path data. (Except admin, and a couple other paths.)

At the end of my urls.py file, I'm using r'^(.*)$'... On my associated view, I make a simple entry into a database - ie: Test(path=capturedpath).save() 

The problem: my database entry is saved twice! Or rather, my view is being loaded twice. I added a global variable to check- if not globals()['already_saved']: Test(path=capturedpath).save() 

If I adjust the path: r'^test/(.*)$'  all works as expected (here my url would be 'mysite.com/test/url/data/to/capture'.)

I'm using django 1.4. Any help/thoughts/suggestions would be much appreciated. 

Thanks!

Jeff Tchang

unread,
Aug 22, 2012, 4:10:49 AM8/22/12
to django...@googlegroups.com
Is it possible you are testing using a browser and it is doing a request for the page and for favicon.ico? That would end up being 2 requests. You can use something like Chrome Developer Tools or Firebug to see.

-Jeff

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

Martin J. Laubach

unread,
Aug 22, 2012, 4:23:01 AM8/22/12
to django...@googlegroups.com
  Also, you should really only do saves on a POST request, never on GETs.

        mjl

James Verran

unread,
Aug 22, 2012, 2:14:25 PM8/22/12
to django...@googlegroups.com
Yes, I think you are right! That would explain the strange behaviour - even in the admin section the page is being loaded. Thank you! 
Reply all
Reply to author
Forward
0 new messages