我试图让我的链接在 Django 中工作。输入时所有 URL 都有效,但我无法弄清楚内部导航。它们都是 app.com/storename/pagename 的格式,所以如果我在 app.com/shoestore/products 上并单击位置,我应该转到 app.com/shoestore/location。我失去了鞋店的部分。
这是一个示例视图:
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})
我的 urls.py:
urlpatterns = 模式('',
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}),
)
和我的导航标签:
<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>