I want to create django popup form in my project [closed]

2024/9/8 9:16:30

I have created fee management system in django.

The problem is I am using simple form and for each form user have to navigate to separate page.

I want to create popup form in django. I have search many websites but can't get solution

enter image description here

In above window when user click on payment button pop-up form will be open. and when user click on submit button changes will be shown in same page.

Can anyone tell me how to solve this? or share code if you have work in same area.

Answer

Why not use bootstrap modals instead?

For example https://pypi.org/project/django-bootstrap-modal-forms/

Examples To see django-bootstrap-modal-forms in action clone the repository and run the examples locally:

$ git clone https://github.com/trco/django-bootstrap-modal-forms.git
$ cd django-bootstrap-modal-forms
$ python -m pip install -r requirements.txt
$ python manage.py migrate
$ python manage.py runserver

Signup form in Bootstrap modal For explanation how all the parts of the code work together see paragraph Usage. To test the working solution presented here clone and run Examples. forms.py

from django.contrib.auth.forms import UserCreationForm
from django.contrib.auth.models import User
from bootstrap_modal_forms.mixins import PopRequestMixin, CreateUpdateAjaxMixinclass CustomUserCreationForm(PopRequestMixin, CreateUpdateAjaxMixin,UserCreationForm):class Meta:model = Userfields = ['username', 'password1', 'password2']

signup.html

{% load widget_tweaks %}<form method="post" action="">{% csrf_token %}<div class="modal-header"><h3 class="modal-title">Sign up</h3><button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button></div><div class="modal-body"><div class="{% if form.non_field_errors %}invalid{% endif %} mb-2">{% for error in form.non_field_errors %}{{ error }}{% endfor %}</div>{% for field in form %}<div class="form-group"><label for="{{ field.id_for_label }}">{{ field.label }}</label>{% render_field field class="form-control" placeholder=field.label %}<div class="{% if field.errors %} invalid{% endif %}">{% for error in field.errors %}<p class="help-block">{{ error }}</p>{% endfor %}</div></div>{% endfor %}</div><div class="modal-footer"><button type="button" class="submit-btn btn btn-primary">Sign up</button></div></form>

views.py

from django.contrib.messages.views import SuccessMessageMixin
from django.urls import reverse_lazy
from django.views import generic
from bootstrap_modal_forms.mixins import PassRequestMixin
from .forms import CustomUserCreationFormclass SignUpView(PassRequestMixin, SuccessMessageMixin, generic.CreateView):form_class = CustomUserCreationFormtemplate_name = 'accounts/signup.html'success_message = 'Success: Sign up succeeded. You can now Log in.'success_url = reverse_lazy('index')

urls.py

from django.urls import path
from . import viewsapp_name = 'accounts'
urlpatterns = [path('signup/', views.SignUpView.as_view(), name='signup')
]

.html file containing modal, trigger element and script instantiating modalForm

<div class="modal fade" tabindex="-1" role="dialog" id="modal"><div class="modal-dialog" role="document"><div class="modal-content"></div></div>
</div><button class="signup-btn btn btn-primary" type="button" name="button">Sign up</button><script type="text/javascript">$(function () {// Sign up button$(".signup-btn").modalForm({formURL: "{% url 'accounts:signup' %}"});});
</script>
https://en.xdnf.cn/q/72921.html

Related Q&A

SVG to PNG with custom fonts in Python

Im using Cairo/RSVG based solution for rasterizing SVG to PNG. Its already beeb described on StackOverflow in Convert SVG to PNG in Python. However, this solution doesnt seem to work with custom fonts.…

How to solve an equation with variables in a matrix in Python?

im coding in Pyhon, and Im working on stereo-correlation. I want to resolve this equation : m = K.T.Mm,K,M are know.where :M is the homogeneous coordinate of a point in the cartesian coordinate system…

how to create a new method with signature of another

How can I copy the signature of a method from one class, and create a "proxy method" with same signature in another ?.I am writing a RPC library in python. The server supports remote calls t…

Converting a full column of integer into string with thousands separated using comma in pandas

Say I have population data stored in a column of a dataframe using pandas in python with Country names as row indices. How do I convert the whole column of numbers into string thousands separator using…

Nested WHILE loops in Python

I am a beginner with Python and trying few programs. I have something like the following WHILE loop construct in Python (not exact). IDLE 2.6.4 >>> a=0 >>> b=0 >>> whil…

Fastest way to drop rows / get subset with difference from large DataFrame in Pandas

Question Im looking for the fastest way to drop a set of rows which indices Ive got or get the subset of the difference of these indices (which results in the same dataset) from a large Pandas DataFram…

Python inheritance: when and why __init__

Im a Python newbie, trying to understand the philosophy/logic behind the inheritance methods. Questions ultimately regards why and when one has to use the __init__ method in a subclass. Example:It seem…

TypeError: A Future or coroutine is required

I try make auto-reconnecting ssh client on asyncssh. (SshConnectManager must stay in background and make ssh sessions when need)class SshConnectManager(object): def __init__(self, host, username, passw…

Python socket closed before all data have been consumed by remote

I am writing a Python module which is communicating with a go program through unix sockets. The client (the python module) write data to the socket and the server consume them.# Simplified version of t…

Python child process silently crashes when issuing an HTTP request

Im running into an issue when combining multiprocessing, requests (or urllib2) and nltk. Here is a very simple code:>>> from multiprocessing import Process >>> import requests >>…