Questions tagged [django-generic-views]

Questions about Django’s built-in generic views, which helps you to avoid repeating common code patterns in every project.

Questions about Django’s built-in generic views, which helps you to avoid repeating common code patterns in every project.

568 questions
17
votes
2 answers

Django: How to login user directly after registration using generic CreateView

With django generic CreateView I can create a new user account, but how can I login this user automatically after registration using this technique? urls.py ... url( r'^signup/$', SignUpView.as_view(), name = 'user_signup'…
17
votes
1 answer

How to access RequestContext in class-based generic views?

I have this path in my urls.py: archive_index_dict = { 'queryset': News.objects.filter(show=True), 'date_field': 'date', 'template_object_name': 'object_list', } ... url(r'^$', 'django.views.generic.date_based.archive_index', …
16
votes
2 answers

override create method in django rest generics CreateAPIView

My views.py of django app is as below, class MemberCreate(generics.CreateAPIView): queryset = members.objects.all() serializer_class = MemberSerializer permission_classes = (permissions.IsAdminUser,) def create(self, serializer): …
15
votes
1 answer

Django/python: 'function' object has no attribute 'as_view'

I am trying to create a list_view for a model queryset. When running my server, it returns : attribute error - 'function' object has no attribute 'as_view'. I would appreciate helping me in solve this. Here's my code: Views.py: @login_required…
sumanth
  • 751
  • 2
  • 15
  • 34
15
votes
2 answers

How does django's View class work

I'm diving into Django's generic views, figuring out how they return a simple HttpResponse object, like a simple view function would. I have written a simple project for testing, and I added some logging commands to the basic View classed defined in…
user1563285
15
votes
2 answers

Django Tutorial: Generic Views. Attribute Error

I'm at the last part of this tutorial. from django.conf.urls import patterns, include, url from django.views.generic import DetailView, ListView from polls.models import Poll urlpatterns = patterns('', url(r'^$', ListView.as_view( …
yasith
  • 8,981
  • 7
  • 27
  • 32
13
votes
1 answer

Problem with class based generic views in Django

I'm trying to write a CRUD application using Djangos class based generic views. Following is the code i wrote to create a new user in the db. from django.views.generic import CreateView from django.contrib.auth.decorators import login_required …
vim
  • 1,098
  • 9
  • 21
13
votes
1 answer

django 'str' object is not callable

I have a problem creating an URL view in django. It gives me this error (ferrol is a Space object): TypeError at /spaces/ferrol/ 'str' object is not callable Request Method: GET Request URL: http://localhost:8000/spaces/ferrol/ Django Version:…
CastleDweller
  • 8,204
  • 13
  • 49
  • 69
12
votes
1 answer

Django - Catch argument in Class based FormView

On my page, i need to display the post detail and a comment form for viewer to post comment. I created 2 generic views: # views.py class PostDetailView (DetailView): model = Post context_object_name = 'post' template_name = 'post.html' def…
Thai Tran
  • 9,815
  • 7
  • 43
  • 64
10
votes
1 answer

Django: CreateView with pre-populated and uneditable fields specified by query string

Let's say we have an app called Closet and it has some models: # closet.models.py class Outfit(models.Model): shirt = models.ForeignKey(Shirt) pants = models.ForeignKey(Trouser) class Shirt(models.Model): desc =…
8one6
  • 13,078
  • 12
  • 62
  • 84
10
votes
4 answers

NoReverseMatch Exception help in Django

I'm fairly new to python and following along with part 4 of the tutorial for the Django framework here. I'm trying to implement generic views for the polls app--my code seems correct (as far as I can tell), but when I try to vote, I get a…
mportiz08
  • 10,206
  • 12
  • 40
  • 42
9
votes
1 answer

Passing URL variables to a class based view

I have just started messing with class based views and I would like to be able to access variables from the URL inside my class. But I am having difficulties getting this to work. I saw some answers but they were all so short I found them to be of…
DisneylandSC
  • 926
  • 1
  • 5
  • 19
9
votes
2 answers

How do I set initial data on a Django class based generic createview with request data

I used Django's generic createview for my model from myproject.app.forms import PersonForm class PersonMixin(object): model = Person form_class = PersontForm class PersonCreateView(PersonMixin, CreateView): pass This works perfectly…
8
votes
2 answers

Django: UpdateView restrict per user

I have a site where users can create and edit their own lists. I'm using the generic view CreateView to allow users to create lists. I would like to use the generic view UpdateView to allow them to edit the lists, but the login_required=True is not…
duduklein
  • 10,014
  • 11
  • 44
  • 55
8
votes
2 answers

Django: extend get_object for class-based views

Being a non-expert Python programmer, I'm looking for feedback on the way I extended the get_object method of Django's SingleObjectMixin class. For most of my Detail views, the lookup with a pk or slugfield is fine - but in some cases, I need to…
Gregor
  • 95
  • 2
  • 4
1
2
3
37 38