Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Django中的链接_Python_Django_Hyperlink - Fatal编程技术网

Python Django中的链接

Python Django中的链接,python,django,hyperlink,Python,Django,Hyperlink,我正在努力让我的链接在Django工作。所有的URL在输入时都可以工作,但我无法理解内部导航。它们的格式都是app.com/storename/pagename,因此如果我在app.com/shoestore/products上并单击location,我应该转到app.com/shoestore/location。我把鞋头的部分弄丢了 以下是一个示例视图: def homepage(request, store_subdomain): store_db, store_products =

我正在努力让我的链接在Django工作。所有的URL在输入时都可以工作,但我无法理解内部导航。它们的格式都是app.com/storename/pagename,因此如果我在app.com/shoestore/products上并单击location,我应该转到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})
My URL.py:

urlpatterns=模式(“”

url(r'^admin/',包括(admin.site.url)),
url(r'^(?P\w+/$),主页),
url(r'^(?P\w+)/products/$,products),
url(r'^(?P\w+)/shoppingcart/$,shoppingcart),
url(r'^(?P\w+)/checkout/$,checkout),
url(r'^static/(?P.*)$,'django.views.static.service',
{'document_root':settings.STATIC_root}),
url(r'^media/(?P.*)$,'django.views.static.service',
{'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>

  • 这里没有魔法。您在导航中编写了根绑定URL。在这种情况下,我建议使用django的urlresolvers中的reverse()函数。

    这里没有魔力。您在导航中编写了根绑定URL。在这种情况下,我建议使用django的urlresolvers中的reverse()函数。

    使用named

    url(r'^(?p\w+/$),主页,name='home')

  • 使用命名

    url(r'^(?p\w+/$),主页,name='home')

  • url(r'^(?p\w+/$,“homepage”,name='homepage'),

    
    
    url(r'^(?p\w+/$,“homepage”,name='homepage'),

    
    
    <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>
    
    <li><a href="{% url home store_subdomain %}">Home</a></li>
    
    <a href="{% url home store_subdomain=value %}">Home</a>