Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Django redirect from form upload

From the page

This page isn’t working. If the problem continues, contact the site owner.
HTTP ERROR 405

From the terminal

Method Not Allowed (POST): /
Method Not Allowed: /
[20/Dec/2021 22:00:27] "POST / HTTP/1.1" 405 0

How to redirect to the same page after page upload click.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

form.html->included in sidebar.html-> included in home.html

<form method = "POST" action='.' enctype="multipart/form-data">
    {% csrf_token %}
    {{ form.as_p }}
    <button type="submit">Upload</button>
</form>

views.py

from django.shortcuts import render
from .forms import UserProfileForm

def index(request):
    print(request.POST)
    return render(request,'home.html')

urls.py

from django.conf import settings
from django.urls import path
from django.views.generic.base import TemplateView # new

urlpatterns = [
    path('', TemplateView.as_view(template_name='home.html'), name='home'), 
]

>Solution :

In your urls.py

Change to:

path(‘ ‘, index, name = ‘home’),

And you also have to import your view in urls.py

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading