I’m trying to get my links working in Django. All the URLs work when typed in, but I can’t figure out the internal navigation. They are all of the format app.com/storename/pagename, so if I’m on app.com/shoestore/products and click on location, I should go to app.com/shoestore/location. I’m losing the shoestore part.
Here’s a sample view:
def homepage(request, store_subdomain):
store_db, store_products = database_selector(store_subdomain)
return render_to_response('base.html',
{'store_name': store_db.name, 'store_subdomain':store_subdomain})
My urls.py:
urlpatterns = patterns(”,
url(r'^admin/', include(admin.site.urls)),
url(r'^(?P<store_subdomain>\w+)/$', homepage),
url(r'^(?P<store_subdomain>\w+)/products/$', products),
url(r'^(?P<store_subdomain>\w+)/shoppingcart/$', shoppingcart),
url(r'^(?P<store_subdomain>\w+)/checkout/$', checkout),
url(r'^static/(?P<path>.*)$', 'django.views.static.serve',
{'document_root': settings.STATIC_ROOT}),
url(r'^media/(?P<path>.*)$', 'django.views.static.serve',
{'document_root': settings.MEDIA_ROOT}),
)
and my navigation tag:
<li><a href = "/">Home</a></li>
<li><a href = "/products/"}>Products</a></li>
<li><a href = "/location/">Location</a></li>
<li><a href="mailto:{{store_db.email}}">Email Us</a> </li>
Use named url patterns.
url(r'^(?P<store_subdomain>\w+)/$', homepage, name='home')