logo
down
shadow

How to check for a POST method in a ListView in Django views? I'm getting a 405 error


How to check for a POST method in a ListView in Django views? I'm getting a 405 error

By : hodoor
Date : November 22 2020, 02:59 PM
I wish did fix the issue. It's because you're making a POST request but you've only defined a GET method. If you add a POST method, it should do the trick :
code :
def post(self, request, *args, **kwargs):
    stuff = request.POST.get('q')
    stuff = self.get_queryset().filter(user__icontains=stuff)
    return render(request, self.template_name, {'stuff': stuff, 'q': q })
def get(self, request, *args, **kwargs):
    stuff = self.get_queryset()
    if request.GET.get('q'):
        q = request.GET.get('q')
        stuff = stuff.filter(user__icontains=q)
    return render(request, self.template_name, {'stuff': stuff, 'q': q }) 


Share : facebook icon twitter icon
Django: ListView with post() method?

Django: ListView with post() method?


By : Naren
Date : March 29 2020, 07:55 AM
I hope this helps you . I am trying to process two forms in a Django class based view. The site contains a form called form (based on GET) for narrowing the list results of the ListView and the second form status_form (based on POST).
code :
# Django is complaining that status_form does not exist,
# result since the post method is not executed
context['status_form'] = self.status_form
context = self.get_context_data(**kwargs)
status_form = context['status_form']
class List(ListView);
    def post(self, request, *args, **kwargs):
        return StatusFormView.as_view()(request) # What ever you need be pass to you form processing view
context['status_form'] = status_form
status_form = context['status_form']
What is the difference between django.views.generic.list.ListView and django.views.generic.ListView in Django?

What is the difference between django.views.generic.list.ListView and django.views.generic.ListView in Django?


By : Thanggun99
Date : March 29 2020, 07:55 AM
it fixes the issue In the fourth part of the Django tutorial, it used the django.views.generic.ListView, but in Class-based views API reference, the ListView is in django.views.generic.list.ListView. What is the difference between django.views.generic.list.ListView and django.views.generic.ListView? , Both are exactly referencing same class.You can check it by
code :
import inspect
from django.views.generic import ListView
print(inspect.getfile(ListView))
from django.views.generic.list import ListView
print(inspect.getfile(ListView)) 
When using ajax with django views, when should I use a method of GET and when should it be POST?

When using ajax with django views, when should I use a method of GET and when should it be POST?


By : A. Berman
Date : March 29 2020, 07:55 AM
I wish this help you Generally speaking, POST is used to "send" something to the server, while GET is used to "fetch" something from the server. It's a good idea to follow the these conventions because that's how must APIs also work.
For reference: https://www.w3schools.com/tags/ref_httpmethods.asp
Can i call the get method in django class based views from the post method

Can i call the get method in django class based views from the post method


By : user1627210
Date : March 29 2020, 07:55 AM
it fixes the issue Technically, this is of course perfectly possible and as simple as return self.get(request, **kwargs) BUT you very certainly DONT want to do that, as it will break the expectations of POST vs GET. The canonical navigation pattern is that a sucessful POST should be followed by a redirect, and is known as the "post-redirect-get" pattern. Note that you can use sessions (directly or with the messages framework) if you want to pass some state (outside database state) from the POST to the GET.
Django 2.1 NoReverseMatch error Using post method in Class Based Views

Django 2.1 NoReverseMatch error Using post method in Class Based Views


By : LearnThere
Date : March 29 2020, 07:55 AM
hop of those help? Url : , Add get_absolute_url method to your model like this :
code :
    def get_absolute_url(self):
        return reverse('problem_detail',kwargs={'slug':self.slug})
{% block body-block %}
<h2>{{problem.p_name}}</h2>
<h5>{{problem.difficulty}}</h5>
<p>{{problem.p_description}}</p>
<form  action= "{{ problem.get_absolute_url }}" method="post"> # Pay Attention here
  {% csrf_token %}
  {{ form.as_p }}
  <button type="submit" > Check </button>
</form>
{% endblock %}
Related Posts Related Posts :
  • What are the centroid of k-means clusters with PCA decomposition?
  • How do mongoengine filter field not null?
  • Categorize results based on Model in haystack?
  • Error installing pycrypto on my mac
  • Can Django ORM has strip field?
  • Python pack / unpack converts to Objective C
  • Python - Selenium Locate elements by href
  • Couldn't iterate over a dictionary context variable in template, despite having all in place, as far as I know?
  • Test if Django ModelForm has instance on customized model
  • Reading excel column 1 into Python dictionary key, column 2 into value
  • AttributeError: 'module' object has no attribute 'timeit' while doing timeit a python function
  • Accessing button using selenium in Python
  • Removing White Spaces in a Python String
  • Sort timestamp in python dictionary
  • How to use Python 2 packages in Python 3 project?
  • retrieve links from web page using python and BeautifulSoup than select 3 link and run it 4 times
  • applying lambda to tz-aware timestamp
  • Having two Generic ListViews on the same page
  • Merging numpy array elements using join() in python
  • pythonic way to parse/split URLs in a pandas dataframe
  • Added iterating over page id in Scrapy, responses in parse method no longer run
  • wanting to add an age gate to my quiz
  • Removing top empty line when writing a text file Python
  • How to use a template html in different folder on Google App Engine python?
  • Access ndarray using list
  • unable to post file+data using python-requests
  • How to test aws lambda functions locally
  • inconsistent plot between matplotlib and seaborn in Python
  • How matplotlib show obvious changes?
  • Project in Python3, reading files, word data
  • Check for specific Item in list without Iteration or find()
  • Unicode encoding when reading from text file
  • Overloaded variables in python for loops?
  • All elements have same value after appending new element
  • Python Threading loop
  • `_pickle.UnpicklingError: the STRING opcode argument must be quoted`
  • Python: How to stop a variable from exceeding a value?
  • python textblob and text classification
  • Django - Context dictionary for attribute inside a class
  • Database is not updated in Celery task with Flask and SQLAlchemy
  • Shapely intersections vs shapely relationships - inexact?
  • How to extract a percentage column from a periodic column and the sum of the column?
  • Zombie ssh process using python subprocess.Popen
  • Python regex to capture a comma-delimited list of items
  • joining string and long in python
  • Value Error in python numpy
  • Check if any character of a string is uppercase Python
  • TensorFlow - why doesn't this sofmax regression learn anything?
  • Python Anaconda Proxy Setup via .condarc file on Windows
  • Creating django objects from emails
  • Get spotify currently playing track
  • Select multiple columns and remove values according to a list
  • Python - How to Subtract a Variable By 1 Every Second?
  • Tkinter unable to alloc 71867 bytes
  • How to add Variable to JSON Python Django
  • CSRF token missing or invalid Django
  • Python: writing to a text file
  • Extracting multiple rows from pandas dataframe and converting to columns
  • Pinging a remote PC with Flask, causing server to block
  • Making a fractal graph using a 2D array?
  • shadow
    Privacy Policy - Terms - Contact Us © animezone.co