I'm very new to Django and definitely not very experienced.
Anyhow, I've startet my own site on the local network and succesfully created an app using Django 1.4. But when I tried to start another app, it only seems to show up on my website under some (in my eyes) specieal circumstances.
Whenever my urls.py file looks like this:
urlpatterns = patterns('',
url(r'^$', 'myapp1.views.home1', name='home1'),
url(r'^$', 'myapp2.views.home2', name='home2'),
The first app is shown on the page, but when I switch them around the second app is shown on the page:
urlpatterns = patterns('',
url(r'^$', 'myapp2.views.home2', name='home2'),
url(r'^$', 'myapp1.views.home1', name='home1'),
as I said, I'm no very experience, so if you need me to provide more information let me know.
Django works by matching a URL pattern to some code that you have written in views.py.
In your case, you are pointing the same pattern (^$) to two view methods. Django will stop when it finds a match, so when you switch the patterns around, it will always match the first entry in the list.
If you change your patterns to:
urlpatterns = patterns('',
url(r'^/two$', 'myapp2.views.home2', name='home2'),
url(r'^$', 'myapp1.views.home1', name='home1'),
Now when you type http://localhost:8000/two home2 will be executed, and when you type http://localhost:8000/ home1 will be executed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With