How to make Django pick new urls immediately

23 views
Skip to first unread message

Kayode Odeyemi

unread,
Oct 6, 2011, 3:07:43 PM10/6/11
to django-users
Hello,

I don't know if I'm the only one experiencing this. I have multiple urls.py in different packages based on
the similarities of the modules. Everytime I add a new url to urls.py, it doesn't take effect immediately. Always returning 404 until
I have to do something... Can't remember what I did.

Is anyone experiencing the same?

--
Odeyemi 'Kayode O.
http://www.sinati.com. t: @charyorde

Yaşar Arabacı

unread,
Oct 6, 2011, 4:43:03 PM10/6/11
to django...@googlegroups.com
maybe you should restart the server? And, do you include new urls in your root url config?

2011/10/6 Kayode Odeyemi <dre...@gmail.com>

--
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.



--
http://yasar.serveblog.net/

Babatunde Akinyanmi

unread,
Oct 7, 2011, 1:24:54 AM10/7/11
to django...@googlegroups.com
With django, when a url is sent to the server, the work flow is that
urls.py is first run to check if an expression that matches the url
submitted is available in the pattern function. If available, it runs
the view function specified in the pattern. This just means that you
don't have to restart your server when you add a new url expression so
I suppose the "something" you did was to correct typos........or you
could be more specific

> --
> 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.
>
>

--
Sent from my mobile device

Kayode Odeyemi

unread,
Oct 7, 2011, 4:20:03 AM10/7/11
to django...@googlegroups.com
2011/10/6 Yaşar Arabacı <yasar...@gmail.com>

maybe you should restart the server? And, do you include new urls in your root url config?

OK! I just found out that if you have urls.py in different packages and these urls.py files are all included in the root package urls.py file of the app, if I have a url (say /post) defined within a python module in the package app.api, I will have to access the url like this http://example.com/api/post and not http://example/post. I was attempting the later which is the reason for the 404.

Regards

Daniel Roseman

unread,
Oct 7, 2011, 4:33:22 AM10/7/11
to django...@googlegroups.com
No, that's not true. The name of the app has nothing to do with it. Rather, it's the name you give when you include the app's URLs:

    (r'^randomname/', include('api.urls'))

That will include the 'api' app's URLs with the prefix 'randomname', so you would do example.com/randomname/post/.
--
DR.

Kayode Odeyemi

unread,
Oct 7, 2011, 4:51:28 AM10/7/11
to django...@googlegroups.com
On Fri, Oct 7, 2011 at 9:33 AM, Daniel Roseman <dan...@roseman.org.uk> wrote:
On Friday, 7 October 2011 09:20:03 UTC+1, Kayode Odeyemi wrote:
2011/10/6 Yaşar Arabacı <yasar...@gmail.com>

maybe you should restart the server? And, do you include new urls in your root url config?

OK! I just found out that if you have urls.py in different packages and these urls.py files are all included in the root package urls.py file of the app, if I have a url (say /post) defined within a python module in the package app.api, I will have to access the url like this http://example.com/api/post and not http://example/post. I was attempting the later which is the reason for the 404.

No, that's not true. The name of the app has nothing to do with it. Rather, it's the name you give when you include the app's URLs:

    (r'^randomname/', include('api.urls'))

That will include the 'api' app's URLs with the prefix 'randomname', so you would do example.com/randomname/post/.

If I understand you clearly, that means for all views in api/views.py which has its urls.py (which is within /api) included in the root package of the app like so: (r'^api/', include('api.urls')), will be accessed like this: http://example.com/api/[url-pattern]?

Andre Terra

unread,
Oct 7, 2011, 8:23:32 AM10/7/11
to django...@googlegroups.com
That is correct.

I believe you could go even further and not even prefix the app's urls, by adding an empty path (r'^', include('api.urls')),

I don't quite remember what the raw string should look like, but this would let you apply your app's url patterns to the root of your domain, which in some cases is useful.


Cheers,
AT

Reply all
Reply to author
Forward
0 new messages