django-views

csrf_exempt for class based views

csrf_exempt for class based views Question: Code: class ErrorReportView(View): def get(self, request, *args, **kwargs): return HttpResponse(‘Hello, World!’) @method_decorator(csrf_exempt) def post(self, request, *args, **kwargs): return HttpResponse(‘Hello, World!’) I use Postman, but I get <p>CSRF verification failed. Request aborted.</p> Documentation: https://docs.djangoproject.com/en/4.1/topics/class-based-views/intro/#decorating-the-class What can I try to resolve this? Asked By: Trts || Source Answers: The csrf_exempt decorator …

Total answers: 1

How to separate user login session and admin login session in django

How to separate user login session and admin login session in django Question: I have created small ecommerce website. User can register and login also created custom admin panel for admin which can product add, update and delete. User and Admin both URLS is different. problem is that when user login into website after I’m …

Total answers: 2

rant_category() got an unexpected keyword argument 'slug'

rant_category() got an unexpected keyword argument 'slug' Question: Running into an rant_category() got an unexpected keyword argument ‘slug’ on my django project. Basically, I just need to get the slug of the #category in my app to show it in the url. Here’s my code: views.py class RantListView(ListView): model = Rant context_object_name = "rants" template_name …

Total answers: 3

Django get Models ID from Zip_longest() function data on HTML

Django get Models ID from Zip_longest() function data on HTML Question: I am working a Django application where I have used python zip_longest function with a the for loop for displaying both the Customer Deposits and Withdrawals in an HTML Table, and I want to get the second zipped list item ID unto a url …

Total answers: 1

How to customise Folium html popups in a for loop in python using .format()?

How to customise Folium html popups in a for loop in python using .format()? Question: I am trying to change the standard popups provided with Folium and make these work with a for loop. I am using Django. I succeeded on change the html, following a few tutorials. However I am struggling to understand how …

Total answers: 1

Using related_name in Django Template

Using related_name in Django Template Question: I have two models: Usecase and Usecase_progress. I’m creating a page where I can see a list of all the use cases with their information + the usecase progress for each use case. Usecase model: class Usecase(models.Model): usecase_id = models.CharField(primary_key=True, max_length=20) usecase_name = models.CharField(max_length=256) user_email = models.ForeignKey(‘User’, models.DO_NOTHING, db_column=’user_email’) …

Total answers: 1

How to restrict Django users from filling a form twice in different sessions

How to restrict Django users from filling a form twice in different sessions Question: I have a form for employees to fill their bio data, I want to restrict the employees from viewing the form more than once. That is after filling the form, you can’t view the empty form anymore, you can only follow …

Total answers: 2

Django-rest-framework IF statement in post method is not executing

Django-rest-framework IF statement in post method is not executing Question: (I will provide full code at the bottom) I am trying to create an API view with django rest framework. I wanted to create a login API so I was first testing out on how to check if a data exists in a field in …

Total answers: 1

How to print HTML content from a Django template in a view?

How to print HTML content from a Django template in a view? Question: Let’s say I have a template called index.html with a bunch of block tags and variables and URLs. I can display it from my view using the render() function like so: def index(request): return render(request, "index.html", {…}) I would like to print …

Total answers: 2

Like button not recording the data

Like button not recording the data Question: I have implemented a like button onto my view_post page, but the like’s aren’t been registered. When the button is clicked the page is redirected correctly but no likes are added. views def get_post(request, slug): try: post = BlogPost.objects.get(slug=slug) except BlogPost.DoesNotExist: messages.error(request, ‘This post does not exist.’) post …

Total answers: 1