Django community: RSS
This page, updated regularly, aggregates Django Q&A from the Django community.
-
Django - display list of all users from auth.models in ListView Django
Hi i am working on a Hotel website and am trying to display list of all the users from the admin site onto my dashboard in a listview class UsersListView(ListView): template_name = 'dashboard/users/userlist.html' login_url = '/login/' redirect_field_name = 'user_list' def get_queryset(self): return User.objects.filter( username=self.request.user ) The above code only displayed the logged in user not all the list. Is there a way to display the active and inactive state of the users? <thead> <tr> <th>SN</th> <th>Users</th> <th>Email</th> <th>Status</th> </tr> </thead> <tbody> {% for user in object_list %} <tr> <td>{{forloop.counter}}</td> <td>{{user.username }}</td> <td>{{user.email}}</td> <td>{{user.is_active}}</td> -
How to send a webhook request to a 3rd party application in django?
i have made an api where i am receiving an api request about the successful payment now in the same code i have to trigger a webhook to an other external application to notify about the payment with a request body.so i was trying to use python's requests to accomplish this, please help me if there is any other way @api_view(['POST']) def cashfree_request(request): if request.method == 'POST': data=request.POST.dict() print(data) payment_gateway_order_identifier= data['orderId'] amount = data['orderAmount'] order=Orders.objects.get(payment_gateway_order_identifier=payment_gateway_order_identifier) payment = Payments(orders=order,amount=amount,) payment.save() URL = "" # external application url where webhook needs to send request_data ={ order:{ 'id':order.id, 'payment_collection_status': transaction_status, 'payment_collection_message': transaction_message } } json_data = json.dumps(request_data) response = requests.post(url = URL, data = json_data) return Response(status=status.HTTP_200_OK -
How to set cookie expiration at browser close on a per-request basis using Django
I want to give users the possibility to decide to have persistent sessions. To do this I added a Remember me checkbox in the login page; if the checkbox is toggled, then the session cookie will expire after 1 week, if not toggled the cookie will expire at browser close. I am encountering some problems forcing the cookie expiration at browser close. I am using the set_expiry method of request.session object. The documentation states this: https://docs.djangoproject.com/en/3.2/topics/http/sessions/#django.contrib.sessions.backends.base.SessionBase.set_expiry set_expiry(value) Sets the expiration time for the session. You can pass a number of different values: - If value is an integer, the session will expire after that many seconds of inactivity. For example, calling request.session.set_expiry(300) would make the session expire in 5 minutes. - If value is a datetime or timedelta object, the session will expire at that specific date/time. Note that datetime and timedelta values are only serializable if you are using the PickleSerializer. - If value is 0, the user’s session cookie will expire when the user’s Web browser is closed. - If value is None, the session reverts to using the global session expiry policy. Reading a session is not considered activity for expiration purposes. Session expiration is computed from … -
How to implement a yoga pose detection(basically a ML model) model on a django web app
I'm currently working on a small project and I am structed with the idea if would be possible to run a model that takes user video as input and gives correction in his pose during a yoga session , through a website ,as I'm good with Django but not be able to find out any way to do it please help and any useful resource lead would be of great help thanks in advance. -
Set up Foreign Key relationship from Django in Angular
FYI: This is very descriptive question, so I hope you will understand my problem. In my Django models.py file I have two models with a Foreign Key relationship: class Work(models.Model): job = models.CharField(max_length = 200, blank = False) def __str__(self): return self.job class Personal(models.Model): name = models.CharField(max_length = 250) work = models.ForeignKey('Work', on_delete = models.CASCADE, null = True) def __str__(self): return self.name For these models I have also set up Django Rest Framework serializers.py class WorkSerializer(serializers.HyperlinkedModelSerializer): class Meta: model = Work fields = ('id', 'bezeichnung') class PersonalSerializer(serializers.HyperlinkedModelSerializer): class Meta: model = Personal fields = ('id', 'nachname', 'dienstart') views.py class WorkViewSet(viewsets.ModelViewSet): queryset = Work.objects.all() serializer_class = WorkSerializer def list(self, request, *args, **kwargs): work = Work.objects.all() serializer = WorkSerializer(work, many = True, context = {'request': request}) return Response(serializer.data) class PersonalViewSet(viewsets.ModelViewSet): queryset = Personal.objects.all() serializer_class = PersonalSerializer # permission_classes = (permissions.IsAuthenticated, ) def list(self, request, *args, **kwargs): personal = Personal.objects.all() serializer = PersonalSerializer(personal, many = True, context = {'request': request}) return Response(serializer.data) This is working perfectly fine. I want the User to set up Personal, and select from the different options of jobs (the jobs to choose from will be set up by me in the backend). So my question is: How do … -
chart js barchart with uneven time interval datapoints, parsed from django date time
I'm having trouble parsing Date Times from django in a way that would make chart.js display the data points (as bars) in uneven time intervals that match their distance from one another. Right now the bars are always equidistant from one another. Also I would like to display the time stamps in the format HH:mm. I've tried 1) new Date("{{ d.isoformat }}") which outputs: Thu May 20 2021 04:28:31 GMT+0300 (Eastern European Summer Time) and 2) new Date("{{ d.isoformat }}").toLocaleTimeString(navigator.language, {hour: '2-digit', minute:'2-digit'}) which outputs 04:28 AM So I'm probably parsing them incorrectly in charts.js with parser: 'HH:mm', and I don't know how to do it correctly in either case. Both options result in equidistant bars. HTML/javascript: var db_labels = []; {% for d in x_val %} db_labels.push(new Date("{{ d.isoformat }}").toLocaleTimeString(navigator.language, {hour: '2-digit', minute:'2-digit'})); {% endfor %} var graphData = { type: 'bar', data: { labels: db_labels, datasets: [{ label: 'PM2.5', data: db_y, backgroundColor: [ 'rgba(73, 198, 230, 0.5)', ], borderWidth: 1 }] }, options: { scales: { xAxes: [{ type: 'time', time: { parser: 'HH:mm', format: 'HH:mm', tooltipFormat: 'HH:mm', unit: 'minute', unitStepSize: 15, displayFormats: { 'minute': 'HH:mm', 'hour': 'HH:mm' }, } }] }, } } I get this kind … -
Django imap backend does not send email to recipients
I'm using django-imap-backend to send email from gmail for activation but somehow my emails do not go to recipient mailboxes but go directly to my email only. Here's my settings EMAIL_BACKEND = 'django_imap_backend.ImapBackend' EMAIL_IMAP_SECRETS = [ { 'HOST': 'imap.gmail.com', 'PORT': 993, # default 143 and for SSL 993 'USER': 'myemail@gmail.com', 'PASSWORD': 'myapppassword', 'MAILBOX': 'django', # Created if not exists 'SSL': True # Default } ] -
Custom image URL to be added to the Django model field
I am creating a model in my app called Products which is defined below:- class Product(models.Model): # Define the fields of the product model name = models.CharField(max_length=100) price = models.IntegerField(default=0) quantity = models.IntegerField(default=0) description = models.CharField(max_length=200, default='', null=True, blank=True) image = models.ImageField(upload_to='market/static/images/products') category = models.ForeignKey(Category, on_delete=models.CASCADE, default=1) # Foriegn key with Category Model store = models.ForeignKey(Store, on_delete=models.CASCADE, default=1) Here I have an image field and I am storing images in the folder market/static/images/products. The same value is stored in my database but I want to be able to store a different URL in my database. In the database, I only want to store static/images/products. How can I change that? -
jsondecodeerror django after deploying on heroku server the django app
JSONDecodeError at /vaccine/handle_vaccine_slots/ Expecting value: line 1 column 1 (char 0) Request Method: POST Request URL: http://systemofreckoning.herokuapp.com/vaccine/handle_vaccine_slots/ Django Version: 3.2.2 Exception Type: JSONDecodeError Exception Value: Expecting value: line 1 column 1 (char 0) Exception Location: /app/.heroku/python/lib/python3.9/json/decoder.py, line 355, in raw_decode Python Executable: /app/.heroku/python/bin/python Python Version: 3.9.5 Python Path: ['/app/.heroku/python/bin', '/app', '/app/.heroku/python/lib/python39.zip', '/app/.heroku/python/lib/python3.9', '/app/.heroku/python/lib/python3.9/lib-dynload', '/app/.heroku/python/lib/python3.9/site-packages'] Server time: Thu, 20 May 2021 09:18:42 +0000 -
Django ListView not working on the template
I am trying for hours on a problem that seems very straightforward and I tried everything but it's not working. I want to display the list of blogs on a template. So, I have these views: from django.views import generic from .models import Blog class BlogList(generic.ListView): queryset = Blog.objects.filter() template_name = 'table_of_contents.html' context_object_name = 'blog_list' class BlogDetail(generic.DetailView): model = Blog template_name = 'blog.html' And this is the table_of_contents.html template where I want to display the list of blogs: {% block table_of_contents %} <p>Just for test</p> {{ blog_list }} {%endblock table_of_contents %} I expect that would display the queryset string on the frontend, but that's not the case. I debugged BlogList using the Django shell and made sure that queryset was not empty. What is the (obvious) detail that I am missing here? -
Django LOGGING in docker problem with log file
Hi i have a problem with my default project configure: now i dont know why log file add something like SELECT .... and when i refresh website nothing happend in log file my settings.py logging # Default logging LOGGING = { 'version': 1, 'disable_existing_loggers': False, 'handlers': { 'file': { 'level': 'DEBUG', 'class': 'logging.FileHandler', 'filename': './logs/debug.log', }, }, 'loggers': { 'django': { 'handlers': ['file'], 'level': 'DEBUG', 'propagate': True, }, }, } my debug.log files problem (0.079) SELECT c.relname, CASE WHEN c.relispartition THEN 'p' WHEN c.relkind IN ('m', 'v') THEN 'v' ELSE 't' END FROM pg_catalog.pg_class c LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace WHERE c.relkind IN ('f', 'm', 'p', 'r', 'v') AND n.nspname NOT IN ('pg_catalog', 'pg_toast') AND pg_catalog.pg_table_is_visible(c.oid) ; args=None (0.070) SELECT "my_default_docker_project_django_migrations"."id", "my_default_docker_project_django_migrations"."app", "my_default_docker_project_django_migrations"."name", "my_default_docker_project_django_migrations"."applied" FROM "my_default_docker_project_django_migrations"; args=() (0.068) SELECT c.relname, CASE WHEN c.relispartition THEN 'p' WHEN c.relkind IN ('m', 'v') THEN 'v' ELSE 't' END FROM pg_catalog.pg_class c LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace WHERE c.relkind IN ('f', 'm', 'p', 'r', 'v') AND n.nspname NOT IN ('pg_catalog', 'pg_toast') AND pg_catalog.pg_table_is_visible(c.oid) ; args=None (0.070) SELECT "my_default_docker_project_django_migrations"."id", "my_default_docker_project_django_migrations"."app", "my_default_docker_project_django_migrations"."name", "my_default_docker_project_django_migrations"."applied" FROM "my_default_docker_project_django_migrations"; args=() (0.072) SELECT c.relname, CASE WHEN c.relispartition THEN 'p' WHEN c.relkind IN ('m', 'v') THEN … -
How to trigger notification sound when onmessage event occur using django channels?
I have created a chat website using django channels and want to play some audio as notification alert when any message was send / received between users. can anyone could help me in resolving it ? -
python manage.py dumpdata Unable to serialize database
I am trying to run the command python manage.py dumpdata > data.json However, I receive such a traceback: CommandError: Unable to serialize database: 'charmap' codec can't encode characters in position 1-4: character maps to <undefined> Exception ignored in: <generator object cursor_iter at 0x0000020E11353820> Traceback (most recent call last): File "C:\Users\Illia\Desktop\MyDjangoStuff\greatkart\venv\lib\site-packages\django\db\models\sql\compiler.py", line 1625, in cursor_iter cursor.close() sqlite3.ProgrammingError: Cannot operate on a closed database. How to solve this issue? -
built real time chat app with graphene(django)
I am working on social media like project. Frontend in react native and backend in django with graphql, database is postgresql. I want to build real time chat app, is it possible to do it with graphene, i searched a lot but grapahene doesnt support subscriptions. i don,t want to use django channels because it needs redis and it will cost more to host it along with psql. Any ideas how to implement it? Thanks -
Different behavior of the wagtail on the server and on the local machine
I have a strange wagtail behaviour. When I start Django on the local machine via run server all works fine, but when it runs on a server I have a follow error: PageClassNotFoundError at /admin/pages/196/edit/ The page 'Цены' cannot be edited because the model class used to create it (core.tablist) can no longer be found in the codebase. This usually happens as a result of switching between git branches without running migrations to trigger the removal of unused ContentTypes. To edit the page, you will need to switch back to a branch where the model class is still present. The same database, the same code base, I was checking the git branch is the same as the local machine. Guys, please help, I'm in my second week of beating this problem. -
Python, Django: get data from select-fields inside a table
inside my app I have a table that contains a select-field in each row. After pressing the submit-button I would like to receive all the selected values inside a list (or something else that's usable): template: <form method="POST"> {% csrf_token %} <table name="table-example"> <thead> ... </thead> <tbody> {% for item in list_example %} <tr> <td>...</td> <td>...</td> <td> <select name="select-example"> {% for item in list_selections %} <option name="option-example" value="{{ item }}">{{ item }}</option> {% endfor %} </select> </td> </tr> {% endfor %} </tbody> </table> <button type="submit">Update</button> </form> When trying to receive data from I only get one field! if request.method == "POST": data = request.POST.get('option-example', None) What am I doing wrong or what am I missing here? Or is this even possible? Thanks for all your help and have a great day! -
Django DateTimeField selected appointment
Lets say that someone booked an appointment. How can I let the date of the appointment un-choosable (not valid) so when he chooses the same date it appears error that the thing is not valid ? -
Cookie's domain set fail Django
I'm using Django for my two project. And I set SESSION_COOKIE_DOMAIN for all of them: SESSION_COOKIE_DOMAIN= ".bvroms.cn" Say one project's domain url is back.bvroms.cn and the other one is akm-back.bvroms.cn But when I go to visit back.bvroms.cn after I 've visited akm-back.bvroms.cn the cookie of akm-back.bvroms.cn is blocked. It showed: This cookie was blocked because neither did the request URL's domain exactly match the cookie's domain, nor was the request URL's domain a subdomain of the cookie's Domain attribute value. My question is why theese two domain were not the subdomain of the SESSION_COOKIE_DOMAIN? Is there something wrong with my settings? Thanks -
Django Queryset from two many-to-many classes
I have been trying to write a Django app that manage school student registration, for that I have two models; Student model & ClassRoom model, these two models are many-to-many related models through a custom model (Enrollment model) as follow: class Student(models.Model): fname = models.CharField(max_length=50) sname = models.CharField(max_length=50) gname = models.CharField(max_length=50) lname = models.CharField(max_length= 50) stdId = models.CharField(max_length= 10) # other student attributes class ClassRoom(models.Model): eduYear = models.ForeignKey(EduYear, on_delete=models.CASCADE) stage = models.ForeignKey(Stage, on_delete=models.CASCADE) stageClass = models.ForeignKey(StageClass, on_delete=models.CASCADE) oneClass = models.CharField(max_length=1) max_std = models.IntegerField(null=True, blank=True) student = models.ManyToManyField(Student, through='Enrollment') class Meta: unique_together = ("stage","stageClass","eduYear","oneClass") def __str__(self): pass return '{} {} {} {} '.format( self.eduYear,self.stage,self.stageClass, self.oneClass) # so, classroom will be as (2001 KG KG1 A) class Enrollment(models.Model): student = models.ForeignKey(Student, on_delete=models.CASCADE) oneClass = models.ForeignKey(OneClass, on_delete=models.CASCADE) EduYear = models.CharField(max_length=9) #Description of education year # other extra fields I provided a data entry screen for the user to save student information, where classRoom information is entered using Django administration (because it almost not changing). The user can link saved student with any classroom by using Enrollment class at any time. that's means some student can be saved without classroom (this is a business requirement), enrolled them to class room could be done later. … -
Python Django: Generate table from SQLite to code in models.py bug
I create table in SQLite and generate code to models.py by cmd: python manage.py inspect > home/models.py, but I can't runserver and have this bug. Please help me!!!!!!!!!!!!!!! PS E:\Code\Python\demoWeb> python manage.py runserver Watching for file changes with StatReloader Exception in thread django-main-thread: Traceback (most recent call last): File "C:\Users\Admin\AppData\Local\Programs\Python\Python39\lib\threading.py", line 954, in _bootstrap_inner self.run() File "C:\Users\Admin\AppData\Local\Programs\Python\Python39\lib\threading.py", line 892, in run self._target(*self._args, **self._kwargs) File "C:\Users\Admin\AppData\Local\Programs\Python\Python39\lib\site-packages\django\utils\autoreload.py", line 64, in wrapper fn(*args, **kwargs) File "C:\Users\Admin\AppData\Local\Programs\Python\Python39\lib\site-packages\django\core\management\commands\runserver.py", line 110, in inner_run autoreload.raise_last_exception() File "C:\Users\Admin\AppData\Local\Programs\Python\Python39\lib\site-packages\django\utils\autoreload.py", line 87, in raise_last_exception raise _exception[1] File "C:\Users\Admin\AppData\Local\Programs\Python\Python39\lib\site-packages\django\core\management\__init__.py", line 375, in execute autoreload.check_errors(django.setup)() File "C:\Users\Admin\AppData\Local\Programs\Python\Python39\lib\site-packages\django\utils\autoreload.py", line 64, in wrapper fn(*args, **kwargs) File "C:\Users\Admin\AppData\Local\Programs\Python\Python39\lib\site-packages\django\__init__.py", line 24, in setup apps.populate(settings.INSTALLED_APPS) File "C:\Users\Admin\AppData\Local\Programs\Python\Python39\lib\site-packages\django\apps\registry.py", line 114, in populate app_config.import_models() File "C:\Users\Admin\AppData\Local\Programs\Python\Python39\lib\site-packages\django\apps\config.py", line 301, in import_models self.models_module = import_module(models_module_name) File "C:\Users\Admin\AppData\Local\Programs\Python\Python39\lib\importlib\__init__.py", line 127, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "<frozen importlib._bootstrap>", line 1030, in _gcd_import File "<frozen importlib._bootstrap>", line 1007, in _find_and_load File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked File "<frozen importlib._bootstrap>", line 680, in _load_unlocked File "<frozen importlib._bootstrap_external>", line 851, in exec_module File "<frozen importlib._bootstrap_external>", line 988, in get_code File "<frozen importlib._bootstrap_external>", line 918, in source_to_code File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed ValueError: source code string cannot contain null bytes -
Django sending gmail failed
I've configured gmail in settings file as following: #gmail_send/settings.py EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend' EMAIL_HOST = 'smtp.gmail.com' EMAIL_HOST_USER = 'yoorusername@gmail.com' EMAIL_HOST_PASSWORD = 'key' #past the key or password app here EMAIL_PORT = 587 EMAIL_USE_TLS = True DEFAULT_FROM_EMAIL = 'default from email' I've turned on less secure app access from google but it's still not working Here's the error : SMTPSenderRefused at /register (530, b'5.7.0 Authentication Required. Learn more at\n5.7.0 https://support.google.com/mail/?p=WantAuthError n6sm1130142pgm.79 - gsmtp', '"default from email"') Request Method: POST Request URL: http://127.0.0.1:8000/register Django Version: 3.2.3 Exception Type: SMTPSenderRefused Exception Value: (530, b'5.7.0 Authentication Required. Learn more at\n5.7.0 https://support.google.com/mail/?p=WantAuthError n6sm1130142pgm.79 - gsmtp', '"default from email"') -
Insert boolean field to database in django
I have this model class category(models.Model): name = models.BooleanField(default=True) def __str__(self): return self.name When I try to insert a new category in python manage.py shell with these commands: (InteractiveConsole) >>> from application.models import category >>> c = category(name='Integrity') >>> c.save() I get this following error: Traceback (most recent call last): File "<console>", line 1, in <module> File "C:\Users\Bruker\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\db\models\base.py", line 754, in save force_update=force_update, update_fields=update_fields) File "C:\Users\Bruker\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\db\models\base.py", line 792, in save_base force_update, using, update_fields, File "C:\Users\Bruker\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\db\models\base.py", line 895, in _save_table results = self._do_insert(cls._base_manager, using, fields, returning_fields, raw) File "C:\Users\Bruker\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\db\models\base.py", line 935, in _do_insert using=using, raw=raw, File "C:\Users\Bruker\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\db\models\manager.py", line 85, in manager_method return getattr(self.get_queryset(), name)(*args, **kwargs) File "C:\Users\Bruker\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\db\models\query.py", line 1254, in _insert return query.get_compiler(using=using).execute_sql(returning_fields) File "C:\Users\Bruker\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\db\models\sql\compiler.py", line 1396, in execute_sql for sql, params in self.as_sql(): File "C:\Users\Bruker\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\db\models\sql\compiler.py", line 1341, in as_sql for obj in self.query.objs File "C:\Users\Bruker\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\db\models\sql\compiler.py", line 1341, in <listcomp> for obj in self.query.objs File "C:\Users\Bruker\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\db\models\sql\compiler.py", line 1340, in <listcomp> [self.prepare_value(field, self.pre_save_val(field, obj)) for field in fields] File "C:\Users\Bruker\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\db\models\sql\compiler.py", line 1281, in prepare_value value = field.get_db_prep_save(value, connection=self.connection) File "C:\Users\Bruker\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\db\models\fields\__init__.py", line 823, in get_db_prep_save return self.get_db_prep_value(value, connection=connection, prepared=False) File "C:\Users\Bruker\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\db\models\fields\__init__.py", line 818, in get_db_prep_value value = self.get_prep_value(value) File "C:\Users\Bruker\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\db\models\fields\__init__.py", line 967, in get_prep_value return self.to_python(value) File "C:\Users\Bruker\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\db\models\fields\__init__.py", line 960, in to_python params={'value': … -
Django connecting to a Redis Server Hosted on Amazon EC2
I am new to Redis. I could setup the Redis server on Amazon Ec2 server and it works locally. Now, I am trying to connect to this server through my Django application but I am unable to do so. I have followed this query and updated my conf.d file to accept remote connections. I have also setup a password for redis server. My settings.py file for CHANNEL_LAYERS in Django looks like this: CHANNEL_LAYERS = { "default": { "BACKEND": "channels_redis.core.RedisChannelLayer", "CONFIG": { #"hosts": [("localhost", 6379)], "hosts": ["ec2-3-134-77-111.us-east-2.compute.amazonaws.com:6379"], }, }, } I think I am not setting up the CHANNEL_LAYERS correctly. Could someone please point me in the correct direction. Thanks for your time in advance. -
How can I use GET and POST on the same form in Django
I have a project wiki using Django and python from CS50W and stuck at a point where i have to check for the title is it exist or not and if it exists i will give message and option to change the title or edit it, now this part is using GET method and if the topic does not exist it will set focus to textarea and user can ad information about the title and save it to new file now this uses methot=POST. If I write the following code my check works createNewPage.html <div class="form-group" style="margin-right: 20%"> <form id="newTitle" action="{% url 'save' %}" method="GET"> {% csrf_token %} {% block newTitle %} <label>{{ newTitle_form.title.label }}</label> {{ newTitle_form.title }} {% endblock %} </form> {% if messages %} <div id="messageDiv" class="alert alert-info" role="alert"> {% for message in messages %} {{ message }} {% endfor %} </div> {% endif %} {% if messages %} <div class="h1 flex-container btn-save-placement" style="height: 0px; padding-top: 0px; margin-right: 0%"> <div> <a role="button" id="changeTopic" class="btn btn-outline-dark" href="{% url 'new_topic' %}">Change</a> <a role="button" class="btn btn-outline-dark" href="{% url 'edit' pagetitle %}">Edit</a> </div> </div> {% endif %} </div> <div class="form-group" style="margin-right: 20%; margin-top: 25px"> {% block textArea %} <label>{{ newText_form.text.label }}</label> {{ … -
How to run django function when a payment is made using client side integration
I want to set change a property of a object when a user pays via paypal (client-side integration). An example of changing proprerty can be: def paid(id): data = User.objects.get(id=id) data.paid=True data.save() I can create a view and do this by redirecting after the user pays. But i think it will be insecure cause the user can go to that url anytime he want and still the changes will be made. So I want to change these things only when the user pays without redirecting or letting the user know about it. How to do this? Thank you:)