Django community: RSS
This page, updated regularly, aggregates Django Q&A from the Django community.
-
Django - how to get data from relationships?
I try to get data over a many-to-many and a one-to-many relationship. view.py class PublisherDetailView(generic.DetailView): model = Publisher template_name = 'store/publisher_detail_view.html' models.py class Publisher(models.Model): name = models.CharField(null=False, max_length=30) image = models.ImageField(upload_to='publisher_images/') class Book(models.Model): title = models.CharField(null=False, max_length=30) description = models.CharField(max_length=1000) publisher = models.ForeignKey(Publisher, on_delete=models.CASCADE) class reader(models.Model): name = models.CharField(max_length=40) book = models.ManyToManyField(Book) publisher_detail_view.html {% for reader in publisher.book_set.readers.all %} <p>{{ reader.name }} </p> {% endfor %} I just want to get all readers from a specfic publisher. What is the right code in the template? publisher.book_set.readers.all makes sense to me (early beginner), but doesn't work -
How To get Dynamic Data Detail Information on another page
[enter image description here][1] [1]: https://i.stack.imgur.com/T5sjy.jpg**strong text****strong text** On One Page It Shows all destionation Images and name But I want To Get Details about specfic place when ever i click on image How To Do It workin on a tourism website -
chat app problem can't click on the target twice - javascript
I am making a chatting app using django, a user when click to make a conversation with someone, if clicked another person, he can't come back to the previous one function getConversation(recipient) { $.getJSON(`/chat/api/v1/message/?target=${recipient}`, function (data) { messageList.children('.message').remove(); for (let i = data['results'].length - 1; i >= 0; i--) { drawMessage(data['results'][i]); } messageList.animate({scrollTop: messageList.prop('scrollHeight')}); }); } please help this made me crazy! -
Delete Heroku migrations
I read advices how to delete migrations but I don't understand what I'm doing and it's not working for me. History. One day I had an issue when I added or renamed a model fields locally. So I was tired with that issue and I deleted all migrations and migrate again. And all was OK. But I remember that I will have a big problem when I will deploy on Heroku. So the days are gone. And now it happened. :((( I make migrations, migrate to a server database. Pushed my code, but.. it wrote me: relation "accounts_goal" does not exist LINE 1: SELECT COUNT(*) AS "__count" FROM "accounts_goal" I understand it happened because locally I have 0001 and 0002 migrations, but on the server there are 0012 and etc. migrations. I think I need to delete all old migrations on the server. But I don't know how to do that. Help me please! Thank you) -
Update all object below deleted object in django models?
I created a class which store data for a chapter in book as shown below class Chapters(models.Model): id = models.AutoField(primary_key=True) chapter_number = models.IntegerField(blank=True) name = models.CharField(max_length=255) slug = models.SlugField(unique=True) def __str__(self): return self.name def save(self, *args, **kwargs): if not self.chapter_number: last_chapter = Chapters.objects.latest('chapter_number') self.chapter_number = last_chapter.chapter_number + 1 self.slug = slugify(self.name) same_occurrence = Chapters.objects.filter(chapter_number=self.chapter_number).first() if same_occurrence: same_occurrence.chapter_number = self.chapter_number + 1 same_occurrence.save() super(Chapters, self).save(*args, **kwargs) now, according to the save function the chapter when add between other chapters ( id name chapter_number 1 ABC 1 2 BCD 2 3 CDE 3 ) then all the below chapters get updated as their chapter number increases by one. add name=XYZ at chapter_number=2 id name chapter_number 1 ABC 1 4 XYZ 2 2 BCD 3 3 CDE 4 but now if I delete 1 or 4 or 5 chapters then the sequence of chapter_number will not change. id name chapter_number 1 ABC 1 4 BCD 2 2 CDE 3 3 XYZ 4 5 FGH 5 7 IJK 6 6 PQR 7 I delete chapter_number 2, 3, 4 then the updated table should be like id name chapter_number 1 ABC 1 5 FGH 2 7 IJK 3 6 PQR 4 not like this id … -
Django : cart = self.session[settings.CART_SESSION_ID] = {} giving me unsupported operand type(s) for +: 'float' and 'str' error
Hi im trying to create a cart with django, i created a class: class Cart(object): def __init__(self, request): self.session = request.session cart = self.session.get(settings.CART_SESSION_ID) if not cart: cart = self.session[settings.CART_SESSION_ID] = {} self.cart = cart and it raises to me unsupported operand type(s) for +: 'float' and 'str' error My settings.py CART_SESSION_ID = 'cart' My cart.py from django.conf import settings from Products.models import Product class Cart(object): def init(self, request): self.session = request.session cart = self.session.get(settings.CART_SESSION_ID) if not cart: cart = self.session[settings.CART_SESSION_ID] = {} self.cart = cart def __iter__(self): for p in self.cart.keys(): self.cart[str(p)]['product'] = Product.objects.get(pk=p) def __len__(self): return sum(item['quantity'] for item in self.cart.values()) def save(self): self.session[settings.CART_SESSION_ID] = self.cart self.session.modified = True def add(self, product_id, quantity=1, update_quantity=False): product_id = str(product_id) if product_id not in self.cart: self.cart[product_id] = {'quantity': 1, 'id': product_id} if update_quantity: self.cart[product_id]['quantity'] += int(quantity) if self.cart[product_id]['quantity'] == 0: self.remove(product_id) self.save() def remove(self, product_id): if product_id in self.cart: del self.cart[product_id] self.save() My Views.py : def add_to_cart(request,product_id): cart = Cart(request) cart.add(product_id) return render(request,'menu_cart.html') i dont know what is wrong with the code please help, thank you. Edit: Full Traceback: TypeError at / unsupported operand type(s) for +: 'float' and 'str' Request Method: GET Request URL: http://127.0.0.1:8000/ Django Version: 4.0.4 Exception Type: … -
How to fix error "The view app.views.uploadform didn't return an HttpResponse object. It returned None instead."?
So I have a form in a html document and I'm trying to use it to add a new item to my django database. Here is the HTML form : <form method="POST" action="{% url 'uploadform' %}" enctype="multipart/form-data"> {% csrf_token %} <label for="name">Name:</label><br> <input type="text" id="name" name="name"><br> <label for="details">Details:</label><br> <input type="text" id="details" name="details"><br> <label for="littype">Type of Literature:</label><br> <input type="text" id="littype" name="littype"><br> <label for="image">Cover:</label><br> <input type="file" id="image" name="image"><br> <input type="submit" value="Submit"> </form> Here is my views.py handling the function : def uploadform(request): if request.method == 'POST': if request.POST.get('name') and request.POST.get('details') and request.POST.get('littype') and request.POST.get('image'): post = PostForm() post.name = request.POST.get('name') post.details = request.POST.get('details') post.littype = request.POST.get('littype') post.image = request.POST.get('image') if PostForm.is_valid(): PostForm.save() return render(request, 'uploadform.html') else: return render(request, 'uploadform.html') Here is my models.py even though i think the issue is in views.py : class PostForm(models.Model): name = models.CharField(max_length=200) details = models.TextField() littype = models.TextField() image = models.FileField(upload_to='app/files/') And finally for the issue, im getting an error saying "The view app.views.uploadform didn't return an HttpResponse object. It returned None instead.". I'm not sure what is causing the error and in addition,if there are any changes I have to make thats stopping the form from being turned into a new item in my database, … -
Nested for loop in html using django to display information from 2 different models
I have a model called Section and a model called SectionInfo. Section has one field and that's name. A user will create a section by giving it a name. SectionInfo has a foreign key section_name which links it to the Section model. I have a few other fields inside SectionInfo such as things like detail, date_created, etc. What I am trying to accomplish here is using a for loop to display section names that have already been created inside or above some cards that I have set up in an html template. Then I want to use a nested loop to gather the data that is tied to that section name which is what the user inputs in for the SectionInfo model. I am able to display the section names correctly, but the issue im having is in the loop inside that loop. The same detail link is being displayed in every section that was made. Information should only be displayed in the chosen section for which it was made. Here is a bit of code to help you understand what I am trying to accomplish. {% load bootstrap5 %} {% load crispy_forms_tags %} {% load static %} {% block … -
When reversing a Django migration with AddField, can the newly column renamed undeleted by Django?
As a proof of concept, I made these two migrations in the simplest possible Django app, polls. Here is migration 0001. # Generated by Django 4.0.5 on 2022-06-15 18:17 from django.db import migrations, models class Migration(migrations.Migration): initial = True dependencies = [ ] operations = [ migrations.CreateModel( name='Question', fields=[ ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), ('question_text', models.CharField(max_length=200)), ], ), ] Here is migration 0002 # Generated by Django 4.0.5 on 2022-06-15 18:17 from django.db import migrations, models class Migration(migrations.Migration): dependencies = [ ('polls', '0001_initial'), ] operations = [ migrations.AddField( model_name='question', name='question_type', field=models.CharField(max_length=200, null=True), ), ] And here is the model. from django.db import models class Question(models.Model): question_text = models.CharField(max_length=200) question_type = models.CharField(max_length=200, null=True) Let's say I've migrated the database, and now want to revert 0002. I run the following command python manage.py sqlmigrate polls 0002 --backwards and get this SQL BEGIN; -- -- Add field question_type to question -- CREATE TABLE "new__polls_question" ("id" integer NOT NULL PRIMARY KEY AUTOINCREMENT, "question_text" varchar(200) NOT NULL); INSERT INTO "new__polls_question" ("id", "question_text") SELECT "id", "question_text" FROM "polls_question"; DROP TABLE "polls_question"; ALTER TABLE "new__polls_question" RENAME TO "polls_question"; COMMIT; Clearly, it's dropping the entire column (by dropping and recreating the table), but I'm curious, could Django be … -
Why will only the top form (in order in Django view) work while the one under it will not?
I have a Django view with two Django forms. Both of them were previously working. Now whichever comes first in the order of code (on top) works. I have tried placing both of the forms on top of the other and whichever one is first works, but the second does not do anything when it is submitted. Does anyone know what is the problem and how to fix this? forms in the views.py #checks if bid form is valid if bid_form.is_valid(): print('!!!!!form is valid') #print("bid form is valid") print(listing.bid) new_bid = float(bid_form.cleaned_data.get("bid")) if (new_bid >= listing_price) and (new_bid > max_bid): bid = bid_form.save(commit=False) bid.listing = listing bid.user = request.user bid.save() print("bid form is saving") else: print(bid_form.errors) print("bid form is not saving") return render(request, "auctions/listing.html",{ "auction_listing": listing, "form": comment_form, "comments": comment_obj, "bidForm": bid_form, "bids": bid_obj, "message": "Your bid needs to be equal or greater than the listing price and greater than any other bids." }) else: print(bid_form.errors, bid_form.non_field_errors) print(bid_form.errors) return redirect('listing', id=id) #checks if comment form is valid if comment_form.is_valid(): print("comment is valid") comment = comment_form.save(commit=False) comment.listing = listing comment.user = request.user comment.save() else: return redirect('listing', id=id) -
Djnago rest framework getting json error for fontend api
I am using nextjs in my fontend. When I am adding media url static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) my api not working and throwing error FetchError: invalid json response body at http://127.0.0.1:8000/blog-api reason: Unexpected token < in JSON at position 0 but when I remove it's working. here is my code: urls.py urlpatterns = [ path('', include('api.urls')), ] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) views.py class BlogViewSet(viewsets.ModelViewSet): queryset = Blog.objects.all() serializer_class = BlogSerializer my nextjs code for calling api: const url = "http://127.0.0.1:8000/blog-api"; const headers = { method: "GET", "Content-Type": "application/json", Accept: "application/json", "User-Agent": "*", Authorization: "Token 8736be9dba6ccb11208a536f3531bccc686cf88d", }; const res = await fetch(url, { headers: headers }); const data = await res.json(); console.log(data); -
whenever I try to import my Model into my APP's view I get this annoying error
so this is my app's view that is called "Movies" from django.shortcuts import render from .models import Movie def content_view(request,*args,**kwargs): obj= Movie.objects.get(id=1), context={'Title':Title, 'Description':obj.Description, 'watch now': obj.Watch_Now, 'imdb': obj.IMDB_Rate, 'RT' : obj.RT_Rate, 'my rate': obj.My_Website_rate } return render(request,'content.html',context) and this is the error I get: Model class src.Movies.models.Movie doesn't declare an explicit app_label and isn't in an application in INSTALLED_APPS and yes my app is in installed app in settings. if I comment the second line that import my model, the server runs okay I've been trying to fix it for past 6 hours but I can't reach any solution. please HELP -
Getting database "test-instance" does not exist while trying to containerize python app
I am trying to containerize a python app and it has a postgres db which is in GCP cloud. But when I build the app its throwing an error telling the database does not exist i am unable to understand what is happening i can connect to the database by using Dbeaver tool but when I run the docker file I can see the logs that say File "/usr/local/lib/python3.9/site-packages/django/db/backends/postgresql/base.py", line 187, in get_new_connection connection = Database.connect(**conn_params) File "/usr/local/lib/python3.9/site-packages/psycopg2/__init__.py", line 127, in connect conn = _connect(dsn, connection_factory=connection_factory, **kwasync) django.db.utils.OperationalError: FATAL: database "test-instance" does not exist Docker file which i used # Pull base image FROM python:3.9 # Set environment variables ENV PYTHONDONTWRITEBYTECODE 1 ENV PYTHONUNBUFFERED 1 # Set work directory WORKDIR /code # Install dependencies COPY requirements.txt /code/ RUN pip install -r requirements.txt # Copy project COPY . /code/ settings.py file how i reach out to the gcp db DATABASES = { 'default': { 'ENGINE': 'django.db.backends.postgresql_psycopg2', 'NAME': 'test-instance', 'USER': 'postgres', 'PASSWORD': 'abcder', 'HOST': '35.224.136.9', 'PORT': '5432', } } -
Cors or Axios Error on Django Server and React frontend project
When trying to connect my react component to the django server after installing corsheaders and adding it to installed apps in settings.py. I am still getting the following error: Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://127.0.0.1:8000/api/teacher/. (Reason: CORS request did not succeed). Status code: (null). I have already installed corsheaders and added it to my settings.py together with its middleware, and put allowed all cors origins in same file. I have also installed axios in react and put the import in my react component -
Error, unable to determine correct filename for 64bit macos for using instapy
Justibbs007@Ibrahims-MacBook-Pro ~ % /usr/local/bin/python3 /Users/Justibbs007/programs/instapy-quickstart-master/quickstart_templates/basic_follow-unfollow_activit y.py InstaPy Version: 0.6.16 .. .. .. .. .. .. .. .. .. .. Workspace in use: "/Users/Justibbs007/InstaPy" Error, unable to determine correct filename for 64bit macos Traceback (most recent call last): File "/Users/Justibbs007/programs/instapy-quickstart-master/quickstart_templates/basic_follow-unfollow_activity.py", line 31, in session = InstaPy(username=insta_username, File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/instapy/instapy.py", line 330, in init self.browser, err_msg = set_selenium_local_session( File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/instapy/browser.py", line 122, in set_selenium_local_session driver_path = geckodriver_path or get_geckodriver() File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/instapy/browser.py", line 38, in get_geckodriver sym_path = gdd.download_and_install()[1] File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/webdriverdownloader/webdriverdownloader.py", line 174, in download_and_install filename_with_path = self.download(version, File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/webdriverdownloader/webdriverdownloader.py", line 129, in download download_url = self.get_download_url(version, os_name=os_name, bitness=bitness) File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/webdriverdownloader/webdriverdownloader.py", line 324, in get_download_url raise RuntimeError(info_message) RuntimeError: Error, unable to determine correct filename for 64bit macos please can someone help me out please -
Prevent celery from running my Django app threads
I have a Django app and I am using celery (with redis) for running processing tasks in the background. In addition, I have a python thread which runs some periodic checks as part of my Django app. Surprisingly, when I am starting celery I see my thread is also running as part of celery. I would like to prevent this behavior and have only one instance of my thread and have it as part of my Django app. How can I prevent it from running in celery? I tested it on a newly created app and see the exact same behavior: settings.py: ... CELERY_BROKER_URL = 'redis://localhost:6379/1' __init__.py: from threading import Thread from time import sleep from .celery import app as celery_app __all__ = ('celery_app',) def mythread(): while True: print("thread is running") sleep(10) new_thread = Thread(target=mythread, daemon=True) new_thread.start() celery.py: import os from celery import Celery os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'myapp.settings') app = Celery('myapp') app.config_from_object('django.conf:settings', namespace='CELERY') app.autodiscover_tasks() -
DM Messages not lining up
Social Media Platform: I am trying to get the image to line up above the sent message as you would have it in most standard DMs: https://i.stack.imgur.com/vyO2b.png But for some reason, the text attached to the image proceeds to layer itself beside the image rather than below the image, as shown in the screenshot below. When I add float: right; to my CSS the image and the text layer horizontally in a strange manner: Not lining up Ideally, the image should be on the same side as the texts from the person who sent the image and should be just above the message that was attached to the image (as is commonplace). The HTML doc the DMs are stored on: thread.html: > {% extends 'landing/base.html' %} {% load crispy_forms_tags %} > > {% block content %} > > <div class="container"> > <div class="row"> > <div class="card col-md-12 mt-5 p-3 shadow-sm"> > {% if thread.receiver == request.user %} > <h5><a href="{% url 'profile' thread.user.profile.pk %}"><img class="rounded-circle post-img" height="50" width="50" > src="{{ thread.user.profile.picture.url }}" /></a> @{{ thread.user > }}</h5> > {% else %} > <h5>@{{ thread.receiver }}</h5> > {% endif %} > </div> > </div> > > {% if message_list.all.count == 0 … -
GUI library in Python to collapse adjustable shapes such as rectangles?
I'm new to Python, and am currently working on web development in Django. I need to have an interface on this website that allows a user to dynamically adjust a rectangular shape that displays this adjustment to them on the website in real time. Does anyone know a way to do this using other Python libraries, and how easily those libraries can be integrated into a Django project? Pretty much I need a way to display to the user a rectangle that they can drag and drop the lengths of on the screen as they desire. Very similar to the MS Word shape drawing tools where the user can pick the edge of and expand or collapse. I have explored different libraries in Python, and have found nothing concrete to do this. Any avenues for exploration would be appreciated. -
Make a booleanfield change based on the input of another field in another form and model
I'm trying to make the Status booeleanField in the class References change based on the choice input of the action charfield in the class Ecran after the form submission. For example if i select "sortir pour production" in the action field, the Status field automatically changes to False and if i choose the "retour en stock" it changes to true. Also i want to change the false/true of the status booleanfield to show up in the list_references template as simple Indicator icons, red circle for false and green circle for true. list_references page NOTE: the ETAT colum is the Status booleanField in class References. suivi_ref the form with the action charfield the form that has the Status booleanfield curerntly i can only change it from here models.py class References(models.Model): Ref = models.CharField(max_length=255, blank=False, null=True) Designation = models.CharField(max_length=100, blank=False, null=True) Indice = models.CharField(max_length=100, blank=False, null=True) Emplacment = models.ForeignKey(place, blank=False, null=True, on_delete=models.SET_NULL) Num = models.ForeignKey(Rayons, blank=True, null=True, on_delete=models.SET_NULL) Client = models.ForeignKey(Client, blank=False, null=True, on_delete=models.CASCADE) Statut = models.BooleanField(default=True) def __str__(self): return self.Ref Action_choice = ( ('Sortie pour production', 'Sortie pour production'), ('Retour en stock', 'Retour en stock'), ) BOOL_CHOICES = ((True, 'OK'), (False, 'NOT OK')) class Ecran(models.Model): Nom_de_technicien = models.CharField(max_length=255, blank=True, null=True) Nom_de_CQ … -
How does Django know the path to my database?
Just following the Django tutorials and decided I would do them with Postgresql instead of SQLlite. I added the following to my settings file and everything worked: DATABASES = { 'default': { 'ENGINE': 'django.db.backends.postgresql', 'NAME': 'django_tutorial', 'USER': 'django_admin', 'PASSWORD': 'password123', 'HOST': '127.0.0.1', 'PORT': '5432' } } django_tutorial=> \dt List of relations Schema | Name | Type | Owner --------+----------------------------+-------+-------------- public | accounts | table | django_admin public | auth_group | table | django_admin public | auth_group_permissions | table | django_admin public | auth_permission | table | django_admin public | auth_user | table | django_admin public | auth_user_groups | table | django_admin public | auth_user_user_permissions | table | django_admin public | django_admin_log | table | django_admin public | django_content_type | table | django_admin public | django_migrations | table | django_admin public | django_session | table | django_admin (11 rows) My question is this - How does Django know where postgresql is located? Originally I thought the name was supposed to be the C:\ path, but it only needed the DB name? Like for example the docs say this about sqllite: The name of the database to use. For SQLite, it’s the full path to the database file. When specifying the path, … -
How do I create a temporary link to an image in Django?
I'm writing a REST API. Users should be able to upload an image and view it. That part is easy, the images get saved to the media root, and serving them is handled separately by NGINX on /media/. The problem is that the user needs to be able to generate a temporary link to their image. It can't be a simple redirect, because what's the point of a temporary link if the end user gets redirected to a permanent link? Is there a way in Django to redirect the request on the backend, fetch the image, and return it to the user on the same URL? If not, what's the proper way to do it? I've looked through Google for some 30 minutes, and couldn't find anything. I'm sorry if it's obvious and my search queries were just wrong. -
implementing structural Json file into Django Rest Framework to create a Rest API
I'm wondering if I can create a model that gets all this Json tree, conserving this structure. I already have 3 separate models with the 3 types: MP & TP & VFD, but I want to group them into 1 model that respects this structure of JSON. what is the structure that I need to make in my models.py? { "devices": { "device": [{ "type": "MN", "time": "18/05/2022, 15:15:15", "vfd_name": "MP1", "SN": "EMSMP001", "plant_name": "plant1", "gatway_name": "gw1", "adress": 1, "baud_rate": 9600, "voltage": 230, "current": 10, "active_power": 2.3, "reactive_power": 0.01, "apparent_power": 2.3, "FP": 0.99, "frequency": 49.98 }, { "type": "TR", "time": "18/05/2022, 15:15:15", "TP_name": "TR1", "SN": "EMSMP002", "plant_name":"plant1", "gatway_name":"gw1", "adress": 1, "baud_rate":1, "UA":1, "UB":1, "UC":1, "UAB":1, "UBC":1, "UAC":1, "IA":1 }, { "type": "VFD", "time": "18/05/2022, 15:15:15", "vfd_name": "MP1" }, { "type": "MN", "time": "18/05/2022, 15:15:15", "vfd_name": "MP1", "SN": "EMSMP001", "plant_name": "plant1", "gatway_name": "gw1", "adress": 1, "baud_rate": 9600, "voltage": 230, "current": 10, "active_power": 2.3, "reactive_power": 0.01, "apparent_power": 2.3, "FP": 0.99, "frequency": 49.98 }, { "type": "TR", "time": "18/05/2022, 15:15:15", "TP_name": "TR1", "SN": "EMSMP002", "plant_name":"plant1", "gatway_name":"gw1", "adress": 1, "baud_rate":1, "UA":1, "UB":1, "UC":1, "UAB":1, "UBC":1, "UAC":1, "IA":1 }, { "type": "VFD", "time": "18/05/2022, 15:15:15", "vfd_name": "MP1" }, { "type": "MN", "time": "18/05/2022, 15:15:15", "vfd_name": … -
How Can I generate and Print Multiple Unique Recharge PIN in Django
I am working on a Ticketing project where I want the admin to be to generate multiple unique numeric PINs that customers can purchase and can be validated on the app for event registration. Here is my Ticket Model class Ticket(models.Model): name =models.CharField(max_length=50) price = models.PositiveIntegerField() pin = models.CharField(max_length=6) def __str__(self): return self.name I want a situation where admin would be able to generate multiple PINs for a particular ticket with a click but don't know how to go about it so someone should please help with the best way of doing it. -
Can't import from psycopg2 on Mac M1 Monterey 12.3.1
After installing psycopg2-binary==2.9.1 via pip install -r requirements.txt, when I run python manage.py runserver command locally in a django project I get the following output and error: main() File "/Users/gabrielnaughton/development/tamato/manage.py", line 25, in main execute_from_command_line(sys.argv) File "/Users/gabrielnaughton/development/tamato/venv/lib/python3.9/site-packages/django/core/management/__init__.py", line 401, in execute_from_command_line utility.execute() File "/Users/gabrielnaughton/development/tamato/venv/lib/python3.9/site-packages/django/core/management/__init__.py", line 395, in execute self.fetch_command(subcommand).run_from_argv(self.argv) File "/Users/gabrielnaughton/development/tamato/venv/lib/python3.9/site-packages/django/core/management/base.py", line 343, in run_from_argv connections.close_all() File "/Users/gabrielnaughton/development/tamato/venv/lib/python3.9/site-packages/django/db/utils.py", line 232, in close_all for alias in self: File "/Users/gabrielnaughton/development/tamato/venv/lib/python3.9/site-packages/django/db/utils.py", line 226, in __iter__ return iter(self.databases) File "/Users/gabrielnaughton/development/tamato/venv/lib/python3.9/site-packages/django/utils/functional.py", line 48, in __get__ res = instance.__dict__[self.name] = self.func(instance) File "/Users/gabrielnaughton/development/tamato/venv/lib/python3.9/site-packages/django/db/utils.py", line 153, in databases self._databases = settings.DATABASES File "/Users/gabrielnaughton/development/tamato/venv/lib/python3.9/site-packages/django/conf/__init__.py", line 82, in __getattr__ self._setup(name) File "/Users/gabrielnaughton/development/tamato/venv/lib/python3.9/site-packages/django/conf/__init__.py", line 69, in _setup self._wrapped = Settings(settings_module) File "/Users/gabrielnaughton/development/tamato/venv/lib/python3.9/site-packages/django/conf/__init__.py", line 170, in __init__ mod = importlib.import_module(self.SETTINGS_MODULE) File "/opt/homebrew/Cellar/python@3.9/3.9.12/Frameworks/Python.framework/Versions/3.9/lib/python3.9/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 972, in _find_and_load_unlocked File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed 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 850, in exec_module File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed File … -
How to run infinite loop in Django and Display Message on template after each Loop without breaking the loop
I need a run a function infinitely until we manually stop it. But after executing each loop we have to display the current loop result in the template. After displaying the result it continues to the next loop. How to execute this process flow. Please advise.