Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to pass DetailView over the 'slug' in url?
    text
    copied!<p>How to pass <a href="https://docs.djangoproject.com/en/1.4/ref/class-based-views/#django.views.generic.detail.DetailView" rel="nofollow">DetailView</a> over the 'slug' in url?</p> <p>First, let's look at my code.</p> <p>urls.py</p> <pre><code>from django.conf.urls import patterns, include, url urlpatterns = patterns('', url(r'^customer/(?P&lt;slug&gt;[^/]+)/$', customerDetailView.as_view()), ) </code></pre> <p>views.py</p> <pre><code>from django.views.generic import DetailView class customerDetailView(DetailView): context_object_name = 'customerDetail' template_name = "customerDetail.html" allow_empty = True model = Customer slug_field = 'name' # 'name' is field of Customer Model </code></pre> <p>Now, my code is like above.</p> <p>And I want to change code like below.</p> <p>urls.py</p> <pre><code>from django.conf.urls import patterns, include, url urlpatterns = patterns('', url(r'^customer/(?P&lt;slug&gt;[^/]+)/$', customer), ) </code></pre> <p>views.py</p> <pre><code>from django.views.generic import DetailView class customerDetailView(DetailView): context_object_name = 'customerDetail' template_name = "customerDetail.html" allow_empty = True model = Customer slug_field = 'name' # 'name' is field of Customer Model def customer(request, slug): if request.method == "DELETE": pass # some code blah blah elif request.method == "POST" pass elif request.method == "GET": return customerDetailView.as_view(slug=slug)(request) # But this line is not working... just causing error TypeError, customerDetailView() received an invalid keyword 'slug' </code></pre> <p>As you know, DetailView need to 'slug' or 'pk'... So I must deliver 'slug' over to the DetailView... But I don't know how do I deliver 'slug'...</p> <p>I'm waiting your answer front of moniter...</p> <p>Thank you!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload