我想让我的链接在Django工作。所有的网址都可以输入,但我搞不清内部导航。它们都是格式app.com/storename/pagename,所以如果我在app.com/shoestore/products点击位置,我应该去app.com/shoestore/位置. 我要失去鞋帮的部分了。在
下面是一个示例视图:
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})
我的网址.py以下内容:
urlpatterns=模式(''
^{pr2}$)
和我的导航标签:
<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>
使用名为url patterns。在
url(r'^(?P<store_subdomain>\w+)/$', homepage, name='home')
url(r'^(?P<store_subdomain>\w+)/$', 'homepage', name='homepage'),
这里没有魔法。您在导航中编写了根绑定的url。在本例中,我建议使用django的urlResolver中的reverse()函数。在
相关问题 更多 >
编程相关推荐