button - Jump to another page after press add buton django add form -
i wan jump page after press button insert table of form
{% extends "index.html" %} {% block title %} <title>add banner</title> {% endblock %} {% block content %} <div class = "container"; align="center"> <h3 >add banner</h3> <form method="post" action="" enctype="multipart/form-data"> {% csrf_token %} {{ form.as_p }} <button type="submit"; onclick="location.href='/banner_list'"; value="insert">add</button> </form> <button style="height:50px;width:100px"; onclick="location.href='/banner_list';" type="button">back</button> </div> {% endblock %}
this template. modifiy template button onclick , things nothing works , view :
def add_form(request): form=bannerform() last=models.banner.objects.last() if not last: id = 1 else: id = last.id if request.method == "post": form = forms.bannerform(request.post, request.files or none) if form.is_valid(): form.cleaned_data['created_by'] new_banner=models.banner() new_banner.id=id+1 print new_banner.id new_banner.name=form.cleaned_data['name'] new_banner.company=form.cleaned_data['company'] new_banner.file=form.cleaned_data['file'] new_banner.file_name=new_banner.file.name new_banner.created_by=form.cleaned_data['created_by'] new_banner.save() return render(request, "add_banner.html",{"form":form})
Comments
Post a Comment