1

I am trying to use Django generic view for CRUD.

I found two resources (1, 2), and bit confused the best and easy approach.

  1. Added below to myapp/urls.py
urlpatterns = patterns('',
    url(r'^$',
        ListView.as_view(
            model= Product)),
)

then it gave an error that,

Exception Type: TemplateDoesNotExist
Exception Value:    
myapp/product_list.html

It worked when I created a file product_list.html. But, do I have to manually write the template? I am sure not.

Also, how to decorate it so that only users of a group has access to it.

Thanks.

1 Answer 1

2

The decorator can be applied inside the urlpatterns like so:

urlpatterns = patterns('',
    url(r'^$', my_decorator(ListView.as_view(model= Product))),
)

Yes you have to manually write the template. Also the name of the template is the_model_name_list.html by default but you can also define a custom template name like so:

urlpatterns = patterns('',
    url(r'^$', my_decorator(ListView.as_view(model= Product,
                                             template_name="custom_name.html"))),
)
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you verymuch. is there a way to extend the admin template. Basically, I like to use the admin template, but as a non-admin user. thanks gain.
This reference can help you on this.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.