2013-02-26 39 views
7

मुझे एक विस्तार दृश्य प्रदर्शित करने के लिए मेरे यूआरएल को कॉन्फ़िगर करने में समस्या हो रही है। इस लिंक पर क्लिक करके: <a href='{% url blog_detail blog.slug %}'>{{ blog.name }}</a>blog.html दिखाता है, जब मैंने सोचा कि यह blog-detail.html दिखाएगा। कोई त्रुटि नहीं है और ब्राउजर बार कहता है: example.com/blog/the-slug, अभी भी blog.html से एचटीएमएल प्रदर्शित करता है, blog-detail.html नहीं। कोई विचार क्यों? आपके विचारों के लिए धन्यवाद।Django Url, विवरण के लिए स्लग पृष्ठ

यूआरएल:

url(r'^blog/', 'myapp.views.blog', name='blog'), 
url(r'^blog/(?P<slug>[\w-]+)/$', 'myapp.views.blog_detail', name='blog_detail'), 

विचार:

def blog(request): 
    blog_list = Blog.objects.all() 
    return render(request, 'blog.html', {'blog_list':blog_list}) 

def blog_detail(request, slug): 
    blog = get_object_or_404(Blog, slug=slug) 
    return render(request, 'blog-detail.html', {'blog':blog}) 

संपादित करें: उत्पादन से @omouse

का अनुरोध इस लिंक पर क्लिक करने से उत्पादन होता है। यह बिल्कुल blog.html जैसा ही है, लेकिन यह blog-detail.html होना चाहिए। Argggg!

<div id='content-wrapper'> 
<section> 
<div class='blog-name'><h2><a href='/blog/test/'>Test</a></h2></div> 
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry&#39;s standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a ... 

<div class='blog-name'><h2><a href='/blog/second-test/'>Second Test</a></h2></div> 
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry&#39;s standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a ... 
</section> 
</div> 
+0

पहले से ही इस एक {{ blog.name }} catherine

+0

हाँ कोशिश है कि धन्यवाद की कोशिश की। अभी भी कोई भाग्य नहीं है। सुनिश्चित नहीं है कि समस्या क्या हो सकती है ... –

+0

क्या आप टेम्पलेट आउटपुट जोड़ सकते हैं? –

उत्तर

22

यूआरएल समस्या हैं, पहले एक सब कुछ (/blog/, /blog/test/, /blog/awdlawdjaawld) से मेल करेंगे, तो आप केवल मैच /blog/ करने के लिए इसे के अंत में डॉलर साइन $ की जरूरत है।

url(r'^blog/$', 'myapp.views.blog', name='blog'), 
url(r'^blog/(?P<slug>[\w-]+)/$', 'myapp.views.blog_detail', name='blog_detail'), 

उपरोक्त सही ढंग से काम करना चाहिए।

This is a good reference for Regular Expressions

+0

बेशक धन्यवाद! –