django-generic-views

Page not found After using UpdateView class

Page not found After using UpdateView class Question: I have a project that requires an update form, I am using the Django generic views, specifically the UpdateView. I Think this is an error with the URL, but I dont find where it is. Error also refers to the url The current path, actualizar_empleado/, didn’t match …

Total answers: 1

Django – Redirect Unauthenticated User trying to access UpdateView to DetailView

Django – Redirect Unauthenticated User trying to access UpdateView to DetailView Question: This is my last brain cell speaking. I have a model called Post with title, body, author, logo and pub_date fields. There is a page in my app that the user can Update/Edit the post. I want the user to be redirected to …

Total answers: 3

How to convert a function based view into class based ListView?

How to convert a function based view into class based ListView? Question: How implement Django.views.generic if earlier used request? from django.shortcuts import render,redirect from django.http import HttpResponse from .models import * from django.contrib.auth import login,logout,authenticate from .forms import * from django.views.generic import ListView # Create your views here. # New class HomePage(ListView): model = Book …

Total answers: 1

How to add two ForeignKey(User) in django model?

How to add two ForeignKey(User) in django model? Question: I have a Group model: class Group(models.Model): leader = models.ForeignKey(User, on_delete=models.CASCADE) name = models.CharField(max_length=55) description = models.TextField() joined = models.ManyToManyField(User, blank=True) and I recently added the ability for the leader to pass over their leadership to a different User. This is fine, but then I noticed …

Total answers: 2

lookup_field Return None In Django get_queryset

lookup_field Return None In Django get_queryset Question: I have a class extend with GenericAPIView , I Can access to the lookup_field in my functions, but I can’t use it in the queryset function. class SellerItemAPIView(GenericAPIView, ListModelMixin): serializer_class = ShopItemSerializer permission_classes = [AllowAny] lookup_field = ‘phone_number’ def get_queryset(self): print(self.lookup_url_kwarg) # It Return None print(self.lookup_field) # It …

Total answers: 1

Expected view to be called with a URL keyword argument named "pk"

Expected view to be called with a URL keyword argument named "pk" Question: I’m writing a test for a Django Rest Framework view following closely the testing documentation Here’s my simple test: def test_patient_detail_api_opens(self): factory = APIRequestFactory() view =PatientDetailApi.as_view() request = factory.get(reverse(‘api_pacjent’, kwargs={‘pk’ :1})) force_authenticate(request, user=self.user) response = view(request) self.assertEqual(response.status_code, 200) This test fails with …

Total answers: 2

Django class-based view: How do I pass additional parameters to the as_view method?

Django class-based view: How do I pass additional parameters to the as_view method? Question: I have a custom class-based view # myapp/views.py from django.views.generic import * class MyView(DetailView): template_name = ‘detail.html’ model = MyModel def get_object(self, queryset=None): return queryset.get(slug=self.slug) I want to pass in the slug parameter (or other parameters to the view) like this …

Total answers: 7