Getting form data in Django middleware - python

What I am basically trying to do is capture data into my middleware from front end, so that I can track the users activity. User activity refers to buttons clicked and data entered into a form.
So I am done with the button part but stuck on getting data filled in the form by the user. I need help with that.
Below is my html and my middleware build in python:
middleware.py:
class TodoappMiddleware(object):
def __init__(self, get_response):
self.get_response = get_response
def __call__(self, request):
response = self.get_response(request)
if request.method == "GET":
f = open("/home/gblp250/Desktop/log", 'a')
f.write("User clicked ")
name = request.GET.get('name')
if not name == 'None':
f.write(str(name))
f.write("\n")
f.close()
elif request.method == 'POST':
f = open("/home/gblp250/Desktop/log", 'a')
f.write("User clicked ")
if request.POST.get("Login"):
nm = request.POST.get("Login")
if not nm == 'None':
f.write("Login\n")
elif request.POST.get("Authorize"):
f.write("Authorize\n")
elif request.POST.get("Assign"):
f.write("Assign\n")
elif request.POST.get("delete_task"):
f.write("Delete task\n")
elif request.POST.get("mark_complete"):
f.write("Mark as complete\n")
elif request.POST.get('authorise_users'):
form = AuthUserCheckbox(request.POST)
if form.is_valid():
ch = form.cleaned_data.get('choice')
print "User then chose "
f.write(ch)
f.close()
html:
{% extends 'todoapp/base.html' %}
{% block title %}Authorize users{% endblock %}
{% block content %}
<h2>Select users to authorize</h2>
<form method="post" action="{% url 'auth_users' %}" id="authorise_users">
{% csrf_token %}
{{ form.choice }}
<br/><input type="submit" value="Authorize" name="Authorize">
<button onclick="location.href='{%url 'dashboard' %}?name=Go back'" type="button">Go back</button>
</form>
{% endblock %}
All the request.POST.get are buttons except for authorise_users, it is a checkbox. I am not able to get the user entered value for that. All buttons clicks I have got but I am not able to get the selected value for authorise_users

Based on the error you are getting (mentioned in a comment to the question), you probably need to change the line
if request.choice.is_valid():
to
if form.choice.is_valid():
or
if form.is_valid():
Does that help to solve the error?

Related

How do I get the current item in the model from the request?

When a submit button is clicked, I want to be able to know what item the user was on. The button would be on an item's page that the user gets taken to when they click on an item. This button is is part of a django form (PlaceBid) that allows the user to bid for the item. So I want to be able to update what the item's highest bid is if the bid is higher than the current highest. This means that I need to know what item the user was viewing.
I also want to save the bid in a model called Bid and in that model I also need to know what listing the bid is for.
So how do I get the correct item from the model?
The models:
Listing() is the model for the item
Bid() is the model for the bid
views.py:
def bid(request):
if request.method == 'POST':
form = PlaceBid(request.POST)
if form.is_valid():
current = Listing.objects.get(pk=request.id) # my attempt to get the current item
highest = current.highest_bid
if form.cleaned_data['bid'] < highest:
obj = Bid()
obj.price = form.cleaned_data['bid']
obj.item = current
obj.user = User.objects.get(pk=request.user.id)
obj.save()
current.highest_bid = form.cleaned_data['bid']
current.save()
return HttpResponseRedirect(request.path_info)
forms.py:
class PlaceBid(forms.Form):
bid = forms.FloatField(required=False, widget=forms.NumberInput(attrs={
'class': 'bid',
}))
html:
<form action=" {% url 'bid' %} " method="post">
{% csrf_token %}
{{ bidForm }}
<input type="submit" value="Place Bid" class="place-bid">
</form>
With the limited code shown, I can only assume at this point that you have a bidding form for each item in a forloop. Example:
{% for item in items %}
...
<form action=" {% url 'bid' %} " method="post">
{% csrf_token %}
{{ bidForm }}
<input type="submit" value="Place Bid" class="place-bid">
</form>
...
{% endfor %}
But here are two methods that can be done...
Use a hidden input field to hold the item object id then retrieve that field name on the server to get the item's id value.
# html
<form action=" {% url 'bid' %} " method="post">
{% csrf_token %}
{{ bidForm }}
<input type="hidden" value="{{ item.id }}" name="item_id">
<input type="submit" value="Place Bid" class="place-bid">
</form>
# views.py
def bid(request):
if request.method == 'POST':
form = PlaceBid(request.POST)
if form.is_valid():
item_id = request.POST.get('item_id', None)
current = Listing.objects.get(id=item_id)
# rest of code follows...
Pass the item's id via the url. (My recommendation)
# html
<form action=" {% url 'bid' item.id %} " method="post">
{% csrf_token %}
{{ bidForm }}
<input type="submit" value="Place Bid" class="place-bid">
</form>
# urls.py
# update the necessary url to accept an id
path('bid/<int:id>/', views.bid, name='bid')
# views.py
def bid(request, id):
if request.method == 'POST':
form = PlaceBid(request.POST)
if form.is_valid():
current = Listing.objects.get(id=id) # id passed to this method used here...
# rest of code follows...
Also, instead of using Listing.objects.get(id=id), I'd suggest using get_object_or_404(Listing, id=id) as this will handle any potential error that Listing.objects.get(id=id) will throw.
You won't get it from the request. Hide it in the form.
class PlaceBid(forms.Form):
bid = forms.FloatField(required=False, widget=forms.NumberInput(attrs={
'class': 'bid',
}))
listing_id = forms.IntegerField(widget=forms.HiddenInput())
Then in your method that displays the form (I'm using function-based views)
def view_listing(request, listing_id)
listing = Listing.objects.get(id=listing_id)
myForm = PlaceBid(initial={"listing_id" : listing_id})
return render("whatever.html", {"listing" : listing, "form" : form })
I suppose another option would be to stash the listing_id in the session, but I try to avoid that.

django how to change database with click button on new window and close, refresh the main page?

I made 'alert list' page. (alert_list.html)
and when I click the button, it renders detail page uses pk on new window. (alert_detail.html)
And there is confirm button on alert_detail.html that change event.event_status value 1 to 0.
But , I have some problem with handle this.
The things what I want to do is..
change Event.event_status value to 0. by click the confirm button
close new window(detail page)
refresh main page(alert list page)
<alert_list.html>
{% for event_alert in event_list %}
{% if event_alert.event_status == 1 %}
<div class="col-1 red">
<div class="p-3 rounded-2" id="dash_board_patient_alert">
{{event_alert.member_id}} {{event_alert.event_type}}
</div>
</div>
{% endif %}
{% endfor %}
{{event_alert_activate_count}}
{{pink_block}}
{% for _ in pink_block %}
<div class="col-1 pink">
<div class="p-3 rounded-2" id="dash_board_patient_alert">
</div>
</div>
{% endfor %}
<alert_detail.html>
{% for event_alert in event_list %}
<form method="POST" class="post-form" action ="{% url 'Alert Update' event_alert.pk %}">
{% csrf_token %}
{{ form }}
<button
type="submit"
class="btn btn-primary"
id="patient_alert_result_confirm">
Confirm
</button>
</form>
{% endfor %}
<alert_update.html>
I don't have any idea.. help me this page
<views.py>
def alert_list(request):
Event.objects.order_by('-event_time')[:12]
event_alert_activate_count = Event.objects.filter(event_status__startswith='1')[:12].count()
pink_block = int(12)
event_list = Event.objects.order_by('-event_time')
context = {
'event_alert_activate_count': event_alert_activate_count,
'event_list' : event_list,
'pink_block' : pink_block
}
return render(request, 'dashboard/alert_list.html', context)
def alertDetail(request,pk):
event = get_object_or_404(Event, pk=pk)
event_list = Event.objects.order_by('-event_time')[:1]
context = {'event_list': event_list,
'event' : event,}
return render(request, 'dashboard/alert_detail.html', context)
def alertUpdate(request,pk):
event = get_object_or_404(Event,pk=pk)
event_list = Event.objects.order_by('-event_time')[:1]
if request.POST :
event_status_form = EventStatusForm(request.POST)
if event_status_form.is_valid():
change_event_status = 0
event.event_status = change_event_status
event_status_form.save()
return HttpResponse('<script type="text/javascript">window.parent.location.href = "/";')
else :
form = EventStatusForm(request.POST)
context = {'event_list': event_list,
'event' : event,
'form' : form,}
return HttpResponse('<script type="text/javascript">window.parent.location.href = "/";')
<model.py>
class Event(models.Model):
member_id = models.ForeignKey(Member, on_delete=models.CASCADE, db_column = 'member_id')
event_type = models.IntegerField(default=0)
room_name = models.CharField(max_length=20)
heart_rate = models.IntegerField(default=0)
breath_rate = models.IntegerField(default=0)
event_status = models.IntegerField(default=0)
event_time = models.DateTimeField(auto_now_add=True, blank=True)
def __str__(self):
return str(self.id)
<forms.py>
class EventStatusForm(forms.Form):
class Meta:
model = Event
fields=('event_status',)
There are various ways to handle this.
Use a form in your details view with a hidden field and assign the confirmation button in your html the role of submit. When the form is submitted, handle the event value switch in your detail view and redirect to main page.
Define another view (e.g. set_event) and respective url. The confirmation button redirects to the new url passing required parameters along. Then handle event switch in your new view and redirect to main page. You will need to take care of permissions in your new view (check if user is allowed to take action).
Use AJAX to submit data and link confirmation button to main page.

Python Flask multiple forms leads to Multiple IDs #csrf_token [duplicate]

I have multiple form on the same page that send post request to same handler
in flask.
I am generating forms using wtforms.
what is the best way to identify which form is submitted ?
I am currently using action="?form=oneform". I think there should be some better method
to achieve the same?
The solution above have a validation bug, when one form cause a validation error, both forms display an error message. I change the order of if to solve this problem.
First, define your multiple SubmitField with different names, like this:
class Form1(Form):
name = StringField('name')
submit1 = SubmitField('submit')
class Form2(Form):
name = StringField('name')
submit2 = SubmitField('submit')
....
Then add a filter in view.py:
....
form1 = Form1()
form2 = Form2()
....
if form1.submit1.data and form1.validate(): # notice the order
....
if form2.submit2.data and form2.validate(): # notice the order
....
Now the problem was solved.
If you want to dive into it, then continue read.
Here is validate_on_submit():
def validate_on_submit(self):
"""
Checks if form has been submitted and if so runs validate. This is
a shortcut, equivalent to ``form.is_submitted() and form.validate()``
"""
return self.is_submitted() and self.validate()
And here is is_submitted():
def is_submitted():
"""Consider the form submitted if there is an active request and
the method is ``POST``, ``PUT``, ``PATCH``, or ``DELETE``.
"""
return _is_submitted() # bool(request) and request.method in SUBMIT_METHODS
When you call form.validate_on_submit(), it check if form is submitted by the HTTP method no matter which submit button was clicked. So the little trick above is just add a filter (to check if submit has data, i.e., form1.submit1.data).
Besides, we change the order of if, so when we click one submit, it only call validate() to this form, preventing the validation error for both form.
The story isn't over yet. Here is .data:
#property
def data(self):
return dict((name, f.data) for name, f in iteritems(self._fields))
It return a dict with field name(key) and field data(value), however, our two form submit button has same name submit(key)!
When we click the first submit button(in form1), the call from form1.submit1.data return a dict like this:
temp = {'submit': True}
There is no doubt when we call if form1.submit.data:, it return True.
When we click the second submit button(in form2), the call to .data in if form1.submit.data: add a key-value in dict first, then the call from if form2.submit.data: add another key-value, in the end, the dict will like this:
temp = {'submit': False, 'submit': True}
Now we call if form1.submit.data:, it return True, even if the submit button we clicked was in form2.
That's why we need to define this two SubmitField with different names. By the way, thanks for reading(to here)!
Update
There is another way to handle multiple forms on one page. You can use multiple views to handle forms. For example:
...
#app.route('/')
def index():
register_form = RegisterForm()
login_form = LoginForm()
return render_template('index.html', register_form=register_form, login_form=login_form)
#app.route('/register', methods=['POST'])
def register():
register_form = RegisterForm()
login_form = LoginForm()
if register_form.validate_on_submit():
... # handle the register form
# render the same template to pass the error message
# or pass `form.errors` with `flash()` or `session` then redirect to /
return render_template('index.html', register_form=register_form, login_form=login_form)
#app.route('/login', methods=['POST'])
def login():
register_form = RegisterForm()
login_form = LoginForm()
if login_form.validate_on_submit():
... # handle the login form
# render the same template to pass the error message
# or pass `form.errors` with `flash()` or `session` then redirect to /
return render_template('index.html', register_form=register_form, login_form=login_form)
In the template (index.html), you need to render both forms and set the action attribute to target view:
<h1>Register</h1>
<form action="{{ url_for('register') }}" method="post">
{{ register_form.username }}
{{ register_form.password }}
{{ register_form.email }}
</form>
<h1>Login</h1>
<form action="{{ url_for('login') }}" method="post">
{{ login_form.username }}
{{ login_form.password }}
</form>
I've been using a combination of two flask snippets. The first adds a prefix to a form and then you check for the prefix with validate_on_submit(). I use also Louis Roché's template to determine what buttons are pushed in a form.
To quote Dan Jacob:
Example:
form1 = FormA(prefix="form1")
form2 = FormB(prefix="form2")
form3 = FormC(prefix="form3")
Then, add a hidden field (or just check a submit field):
if form1.validate_on_submit() and form1.submit.data:
To quote Louis Roché's:
I have in my template :
<input type="submit" name="btn" value="Save">
<input type="submit" name="btn" value="Cancel">
And to figure out which button was passed server side I have in my views.py file:
if request.form['btn'] == 'Save':
something0
else:
something1
A simple way is to have different names for different submit fields. For an
example:
forms.py:
class Login(Form):
...
login = SubmitField('Login')
class Register(Form):
...
register = SubmitField('Register')
views.py:
#main.route('/')
def index():
login_form = Login()
register_form = Register()
if login_form.validate_on_submit() and login_form.login.data:
print "Login form is submitted"
elif register_form.validate_on_submit() and register_form.register.data:
print "Register form is submitted"
...
As the other answers, I also assign a unique name for each submit button, for each form on the page.
Then, the flask web action looks like below - note the formdata and obj parameters, which help to init / preserve the form fields accordingly:
#bp.route('/do-stuff', methods=['GET', 'POST'])
def do_stuff():
result = None
form_1 = None
form_2 = None
form_3 = None
if "submit_1" in request.form:
form_1 = Form1()
result = do_1(form_1)
elif "submit_2" in request.form:
form_2 = Form2()
result = do_2(form_2)
elif "submit_3" in request.form:
form_3 = Form3()
result = do_3(form_3)
if result is not None:
return result
# Pre-populate not submitted forms with default data.
# For the submitted form, leave the fields as they were.
if form_1 is None:
form_1 = Form1(formdata=None, obj=...)
if form_2 is None:
form_2 = Form2(formdata=None, obj=...)
if form_3 is None:
form_3 = Form3(formdata=None, obj=...)
return render_template("page.html", f1=form_1, f2=form_2, f3=form_3)
def do_1(form):
if form.validate_on_submit():
flash("Success 1")
return redirect(url_for(".do-stuff"))
def do_2(form):
if form.validate_on_submit():
flash("Success 2")
return redirect(url_for(".do-stuff"))
def do_3(form):
if form.validate_on_submit():
flash("Success 3")
return redirect(url_for(".do-stuff"))
I haven't used WTForms but should work regardless. This is a very quick and simple answer; all you need to do is use different values for the submit button. You can then just do a different def based on each.
In index.html:
<div>
<form action="{{ url_for('do_stuff')}}" method="POST">
<h1>Plus</h1>
<input type = "number" id = "add_num1" name = "add_num1" required><label>Number 1</label><br>
<input type = "number" id = "add_num2" name = "add_num2" required><label>Number 2</label><br>
<input type = "submit" value = "submit_add" name = "submit" ><br>
</form>
<p>Answer: {{ add }}</p>
</div>
<div>
<form action="{{ url_for('do_stuff')}}" method="POST">
<h1>Minus</h1>
<input type = "number" id = "min_num1" name = "min_num1" required><label>Number 1</label><br>
<input type = "number" id = "min_num2" name = "min_num2" required><label>Number 2</label><br>
<input type = "submit" value = "submit_min" name = "submit"><br>
</form>
<p>Answer: {{ minus }}</p>
</div>
in app.py:
#app.route('/',methods=["POST"])
def do_stuff():
if request.method == 'POST':
add = ""
minus = ""
if request.form['submit'] == 'submit_add':
num1 = request.form['add_num1']
num2 = request.form['add_num2']
add = int(num1) + int(num2)
if request.form['submit'] == 'submit_min':
num1 = request.form['min_num1']
num2 = request.form['min_num2']
minus = int(num1) - int(num2)
return render_template('index.html', add = add, minus = minus)
Well here is a simple trick
Assume you Have
Form1, Form2, and index
Form1 <form method="post" action="{{ url_for('index',formid=1) }}">
Form2 <form method="post" action="{{ url_for('index',formid=2) }}">
Now In index
#bp.route('/index', methods=['GET', 'POST'])
def index():
formid = request.args.get('formid', 1, type=int)
if formremote.validate_on_submit() and formid== 1:
return "Form One"
if form.validate_on_submit() and formid== 2:
return "Form Two"
I normally use a hidden tag that works as an identifier.
Here is an example:
class Form1(Form):
identifier = StringField()
name = StringField('name')
submit = SubmitField('submit')
class Form2(Form):
identifier = StringField()
name = StringField('name')
submit = SubmitField('submit')
Then you can add a filter in view.py:
....
form1 = Form1()
form2 = Form2()
....
if form1.identifier.data == 'FORM1' and form1.validate_on_submit():
....
if form2.identifier.data == 'FORM2' and form2.validate_on_submit():
....
and finally in the HTML:
<form method="POST">
{{ form1.indentifier(hidden=True, value='FORM1') }}
</form>
<form method="POST">
{{ form2.indentifier(hidden=True, value='FORM2') }}
</form>
If you do it like this in the if statement it will check what was the identifier and if its equal it will run the form stuff you have in your code.
Example: Multiple WTForm in single html page
app.py
"""
Purpose Create multiple form on single html page.
Here we are having tow forms first is Employee_Info and CompanyDetails
"""
from flask import Flask, render_template, request
from flask_wtf import FlaskForm
from wtforms import StringField, IntegerField, FloatField, validators
from wtforms.validators import InputRequired
app = Flask(__name__)
app.config['SECRET_KEY'] = 'Thisisasecret'
class EmployeeInfo(FlaskForm):
"""
EmployeeInfo class will have Name,Dept
"""
fullName = StringField('Full Name',[validators.InputRequired()])
dept = StringField('Department',[validators.InputRequired()])
class CompanyDetails(FlaskForm):
"""
CompanyDetails will have yearOfExp.
"""
yearsOfExp = IntegerField('Year of Experiece',[validators.InputRequired()])
#app.route('/', methods = ['GET','POST'] )
def index():
"""
View will render index.html page.
If form is validated then showData.html will load the employee or company data.
"""
companydetails = CompanyDetails()
employeeInfo = EmployeeInfo()
if companydetails.validate_on_submit():
return render_template('showData.html', form = companydetails)
if employeeInfo.validate_on_submit():
return render_template('showData.html', form1 = employeeInfo)
return render_template('index.html',form1 = employeeInfo, form = companydetails)
if __name__ == '__main__':
app.run(debug= True, port =8092)
templates/index.html
<html>
<head>
</head>
<body>
<h4> Company Details </h4>
<form method="POST" action="{{url_for('index')}}">
{{ form.csrf_token }}
{{ form.yearsOfExp.label }} {{ form.yearsOfExp }}
<input type="submit" value="Submit">
</form>
<hr>
<h4> Employee Form </h4>
<form method="POST" action="{{url_for('index')}}" >
{{ form1.csrf_token }}
{{ form1.fullName.label }} {{ form1.fullName }}
{{ form1.dept.label }} {{ form1.dept }}
<input type="submit" value="Submit">
</form>
</body>
</html>
showData.html
<html>
<head>
</head>
<body>
{% if form1 %}
<h2> Employee Details </h2>
{{ form1.fullName.data }}
{{ form1.dept.data }}
{% endif %}
{% if form %}
<h2> Company Details </h2>
{{ form.yearsOfExp.data }}
{% endif %}
</body>
</html>

SelectMultipleField default value is not being selected on HTML

c.ingredientsI am creating a Flask sample app for learning purposes and I have a Form called CocktailForm that contains a SelectMultipleField. This form should be used for creating new cocktails objects as well as for updating them:
class CocktailForm(Form):
name = StringField('What is the coktail\'s name?', validators=[Required()])
ingredients = SelectMultipleField('Ingredients',
coerce=int,
)
submit = SubmitField('Submit')
For editing I want to load the same form with the cocktail data. It works for name, and for loading all choices but I also want to select those choices that are ingredients of that cocktail:
#main.route('/edit/<int:id>', methods=['GET', 'POST'])
def edit(id):
try:
c = Cocktail.query.filter(Cocktail.id == id).one()
form = CocktailForm()
form.ingredients.choices = [(i.id, i.name) for i in Ingredient.query.all()]
if form.validate_on_submit():
c.name = form.name.data
cocktail_ingredients = Ingredient.query.filter(Ingredient.id.in_(form.ingredients.data)).all()
c.ingredients.extend(cocktail_ingredients)
db.session.commit()
else:
form.name.data = c.name
form.ingredients.default = [(i.id, i.name) for i in c.ingredients]
return render_template('new.html', form=form)
except Exception, e:
print e
return redirect(url_for('.index'))
I get unexpected results since on the HTML those choices are not displayed but when I submit the form it seems like those choices are always selected even if you select a new ones.
The template is quite simple:
{% extends "base.html" %}
{% import "bootstrap/wtf.html" as wtf %}
{% block title %}Cocktails{% endblock %}
{% block page_content %}
<div class="page-header">
<h1>New Cocktail</h1>
{{ wtf.quick_form(form) }}
</div>
{% endblock %}
This is what you can see in in the browser. I am editing Gintonic cocktail which is composed of gin and tonic. However they are not displayed as selected:
Browser
Thanks in advance, any tip will be appreciated
The line form.ingredients.default = [(i.id, i.name) for i in Ingredient.query.all()] does not set the selected values. You want to change it to be form.ingredients.data = [i.id for i in c.ingredients].
You should have a redirect/render_template in the validate block, but that is optional.

Use two different forms in same template

I am trying to write a condition where if 1st part is ok then 2nd part will show.I wrote my forms.py in a following way :
class SubmissionForm(forms.Form):
first_name=forms.CharField(max_length=120, required=True)
last_name=forms.CharField(max_length=120, required=True)
class UploadForm(forms.Form):
file1 = forms.Field(label='File1', widget = forms.FileInput,required = True )
file2 = forms.Field(label='File1', widget = forms.FileInput, required = True )
In my views.py:
def submission(request):
validform=False
title="Please submit your data"
form = SubmissionForm(request.POST)
contextsumission={"title":title, "form":form}
if form.is_valid():
first_name = form.cleaned_data.get("first_name")
last_name = form.cleaned_data.get("last_name")
validform=True
if validform:
contextupload={"title":"Please upload your files","valid":True}
return render(request, 'submission.html', contextupload)
form2 = UploadForm(request.FILES)
contextsumission={"title":'Upload files', "form2":form2}
if form2.is_valid():
file1 = form2.request.FILES.get("file1")
file2 = form2.request.FILES.get("file2")
contextsumission={"title":"Thank you for your data submission"}
return render(request, 'submission.html', contextsumission)
And I have tried to write my template in a following way
{% if valid %}
<h1 class ='text-align-center', style="color: blue;"> {{ title }} </h1>
<form method ='POST' enctype="multipart/form-data" action =''> {% csrf_token %}
{{form2|crispy}}
<input class='btn btn-primary', type='submit', value='Upload'>
</form>
{% else %}
<h1 class ='text-align-center', style="color: blue;"> {{ title }} </h1>
<form method ='POST' enctype="multipart/form-data" action =''> {% csrf_token %}
{{form|crispy}}
<input class='btn btn-primary', type='submit', value='Submit'>
</form>
{% endif %}
I can see my SubmissionForm clearly in template but after pressing submit button I want to show file upload form but it is not working.
Anyone can please tell me where I need to change my code?
Thanks
Paul
Yes I have realized that and modified my code but still I have problem and def submission function is not validating two forms!! That means when ever I am trying to do form2.is_valid(), is returning false.
def submission(request):
title="Please submit your data"
form = SubmissionForm(request.POST)
contextsubmission={"title":title, "form":form}
if form.is_valid():
first_name = form.cleaned_data.get("first_name")
last_name = form.cleaned_data.get("last_name")
form2 = UploadForm(request.FILES)
contextsubmission ={"title":"Please upload your files","form2":form2,"valid":True}
if form2.is_valid():
file1 = form2.request.FILES.get("file1")
file2 = form2.request.FILES.get("file2")
contextbsumission={"title":"Thank you for your data submission"}
return render(request, 'submission.html', contextsubmission)

Categories

Resources