Django not reading the URLConf (urls.py)

1,325 views
Skip to first unread message

Rodrigo

unread,
Feb 27, 2010, 3:34:42 PM2/27/10
to Django users
If I update any line on the urls.py, this doesn't reflect on the
server. I can even DELETE the file, and all the urls are still
working. I've tried restarting runserver many times, even restarting
the computer, and nothing happens.

The last test I did was deleting settings.py, to see if there was some
kind of problem of other type, but the settings.py does get read,
since runserver gave me this error:
$ python manage.py runserver
Error: Can't find the file 'settings.py' in the directory containing
'manage.py'. It appears you've customized things.
You'll have to run django-admin.py, passing it your settings module.
(If the file settings.py does indeed exist, it's causing an
ImportError somehow.)

So, I restored settings.py and with urls.py deleted, the server keeps
resolving old urls.

piz...@gmail.com

unread,
Feb 27, 2010, 4:05:18 PM2/27/10
to django...@googlegroups.com
Did you delete the .pyc files? Python generates a compiled version of
the file, and if you don't delete it, it never get's updated. At
least it's the problem I have. So if you update views.py and don't
delete the old view.pyc file, it will work as the old version.

> --
> 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
> +unsub...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/
> group/django-users?hl=en.
>

Karen Tracey

unread,
Feb 27, 2010, 4:22:16 PM2/27/10
to django...@googlegroups.com
On Sat, Feb 27, 2010 at 4:05 PM, piz...@gmail.com <piz...@gmail.com> wrote:
Did you delete the .pyc files? Python generates a compiled version of the file, and if you don't delete it, it never get's updated. At least it's the problem I have. So  if you update views.py and don't delete the old view.pyc file, it will work as the old version.


You should not have to manually delete .pyc files when you update the corresponding .py file -- Python should automatically notice the modification date/time of the files do not match and re-generate the .pyc file based on the new contents of the .py file.

It's only when you flat-out delete a .py file that you need to remember to delete its .pyc file as well, because in that case Python can still see the module as existing even though the .py file is gone.

Karen

Kenneth Loafman

unread,
Feb 27, 2010, 6:31:26 PM2/27/10
to django...@googlegroups.com
Karen Tracey wrote:
> On Sat, Feb 27, 2010 at 4:05 PM, piz...@gmail.com
> <mailto:piz...@gmail.com> <piz...@gmail.com <mailto:piz...@gmail.com>>

That's the way it *should* work, however, if you are running under a web
server (runserver, Apache, Lighttpd), you need to manually delete the
.pyc files and restart the server.

...Ken

Karen Tracey

unread,
Feb 27, 2010, 7:03:39 PM2/27/10
to django...@googlegroups.com

If you are routinely needing to delete .pyc files after making code changes in the corresponding .py files, something is broken. The post I responded to stated: "Python generates a compiled version
of the file, and if you don't delete it, it never get's updated." That is not commonly true. Python compares the modification date/time of the .pyc file to same info for the .py file and if the .pyc file is out of date the existing .pyc file is ignored and a new one is regenerated from the current source. If this mechanism is not working on some system, it would be a good idea to track down why, because having to remember to delete .pyc files when changing code is bound to lead to headaches.

The only times I have to manually delete .pyc files are when I have deleting the corresponding .py files, or done a major restructuring and moved things around. I've never had to delete .pyc files for simple code changes. Running under a webserver or not makes no difference in this. Where running under a web server may make a difference is in the need to restart the server to get it to see changes. You generally don't need to do that for runserver, but usually do for production setups. You do not, however, need to delete .pyc files -- you just need to restart the server.

Karen
 

Kenneth Loafman

unread,
Feb 27, 2010, 7:45:25 PM2/27/10
to django...@googlegroups.com
Karen Tracey wrote:
> On Sat, Feb 27, 2010 at 6:31 PM, Kenneth Loafman
> <kenneth...@gmail.com <mailto:kenneth...@gmail.com>> wrote:
>
> Karen Tracey wrote:
> > On Sat, Feb 27, 2010 at 4:05 PM, piz...@gmail.com
> <mailto:piz...@gmail.com>
> > <mailto:piz...@gmail.com <mailto:piz...@gmail.com>>
> <piz...@gmail.com <mailto:piz...@gmail.com> <mailto:piz...@gmail.com

Forget headaches, think full-on head-banger migraines! ;-)

> The only times I have to manually delete .pyc files are when I have
> deleting the corresponding .py files, or done a major restructuring and
> moved things around. I've never had to delete .pyc files for simple code
> changes. Running under a webserver or not makes no difference in this.
> Where running under a web server may make a difference is in the need to
> restart the server to get it to see changes. You generally don't need to
> do that for runserver, but usually do for production setups. You do not,
> however, need to delete .pyc files -- you just need to restart the server.

I listed runserver above, but its not normally a problem.

The problem only appears when you do an update of the .py files while
either Apache or Lighttpd are running. For some reason, even a restart
of the servers will not always catch the modification of the .py file.
Not sure why this is, but I've run into this on multiple Linux distros,
multiple versions of Python and Django, and multiple versions of web
servers.

...Ken

piz...@gmail.com

unread,
Feb 27, 2010, 9:23:12 PM2/27/10
to django...@googlegroups.com
El 28/02/2010, a las 1:03, Karen Tracey wrote:
>
> If you are routinely needing to delete .pyc files after making code
> changes in the corresponding .py files, something is broken. The
> post I responded to stated: "Python generates a compiled version
> of the file, and if you don't delete it, it never get's updated."
> That is not commonly true. Python compares the modification date/
> time of the .pyc file to same info for the .py file and if the .pyc
> file is out of date the existing .pyc file is ignored and a new one
> is regenerated from the current source. If this mechanism is not
> working on some system, it would be a good idea to track down why,
> because having to remember to delete .pyc files when changing code
> is bound to lead to headaches.
>
> The only times I have to manually delete .pyc files are when I have
> deleting the corresponding .py files, or done a major restructuring
> and moved things around. I've never had to delete .pyc files for
> simple code changes. Running under a webserver or not makes no
> difference in this. Where running under a web server may make a
> difference is in the need to restart the server to get it to see
> changes. You generally don't need to do that for runserver, but
> usually do for production setups. You do not, however, need to
> delete .pyc files -- you just need to restart the server.
>
> Karen
>

Yes Karen, that's what I thought from the beginning, something is
broken in my Python installation, I'll explain it better. I'm
currently using django dev server and it doesn't update the .pyc
files, let's say I just change a line in the models, I have to delete
the models.pyc file because python doesn't update i, if it helps,
timestamps difer just seconds (I make quick changes).

This happens to me even on other programs where every change I make,
I have to delete manually the .pyc file. As someone said before is
like head-banging. How can I track down this problem? I'm not a
programmer, this is just a hobby.

I'll test this on other python installation I have on my mac, just in
case. Thanks everybody, and forgive my bad english ;)

Prabhu

unread,
Feb 27, 2010, 9:24:33 PM2/27/10
to Django users
Did you check ROOT_URLCONF in settings.py?

Karen Tracey

unread,
Feb 27, 2010, 10:57:02 PM2/27/10
to django...@googlegroups.com
On Sat, Feb 27, 2010 at 9:23 PM, piz...@gmail.com <piz...@gmail.com> wrote:
Yes Karen, that's what I thought from the beginning, something is broken in my Python installation, I'll explain it better. I'm currently using django dev server and it doesn't update the .pyc files, let's say I just change a line in the models, I have to delete the models.pyc file because python doesn't update i, if it helps, timestamps difer just seconds (I make quick changes).

This happens to me even on other programs where every change I make, I have to delete manually the .pyc file. As someone said before is like head-banging. How can I track down this problem? I'm not a programmer, this is just a hobby.


I'd ask in someplace like comp.lang.python. It's not behavior I've experienced nor seen reported before.

Karen

Rodrigo

unread,
Feb 28, 2010, 5:05:31 AM2/28/10
to Django users
I checked the ROOT_URLCONF and it was fine, and deleted all the *.pyc,
without good results, but finally I found the problem. There was a
copy of the same project in some other folder under the PYTHONPATH, so
there was some kind of collision.
Thanks everybody for helping me out.
Reply all
Reply to author
Forward
0 new messages