Django community: Django Q&A RSS
This page, updated regularly, aggregates Django Q&A from the Django community.
-
How to change SpectacularSwaggerView's authentication_classes in drf_spectacular?
I have a class that inherits from SpectacularSwaggerView. When I call that view, it shows two authentication methods. basicAuth and cookieAuth. I want to use a custom authentication or maybe use no authentication at all. but when I set authentication_classes attribute like this: class CustomSpectacularSwaggerView(SpectacularSwaggerView): authentication_classes = [ CustomAuthentication, ] it shows the same two authentication methods. How can I change that? -
lib-sodium/pynacl errors while building arm64 Alphine-Python images for Python/Django
Summary: I am trying to build an ARM64 image for my project to be able to run it faster locally on my macbook M1 (pro) machine, instead of using normal x64 images which run extremely slow (long startup time, long response time for local dev HTTP server, long test running times). I have the following docker file: FROM arm64v8/python # Install system dependencies RUN apt-get update && apt-get install -y \ git \ curl \ libpq-dev \ build-essential \ libssl-dev \ libffi-dev # Install Node.js for ARM64 RUN curl -fsSL https://deb.nodesource.com/setup_16.x | bash - RUN apt-get install -y nodejs # Set the working directory in the container WORKDIR /app # Install Python dependencies RUN pip install --no-cache-dir cryptography RUN pip install --no-cache-dir pyNaCl==1.3.0 # Copy the requirements.txt file to the container COPY requirements.txt . # Install additional Python dependencies RUN pip install --no-cache-dir -r requirements.txt # Copy the Django project files to the container COPY . . # Expose the Django development server port EXPOSE 8000 # Start the Django development server CMD ["python", "manage.py", "runserver", "0.0.0.0:8000"] requirements.txt: autopep8==1.6.0 kombu>=5.0.0 # celery dependency celery==5.0.0 dj-database-url==0.5 django==3.2.13 django-bootstrap4==2.2.0 django-cors-headers==3.4.0 django-debug-toolbar==3.2.1 django-phonenumber-field==4.0.0 django-safedelete==0.5.6 djangorestframework==3.13.0 djangorestframework-xml==2.0.0 django-model-utils==4.2.0 gunicorn==20.0.4 ipdb==0.13.3 jedi==0.18.1 # ipython dependency … -
Update the whole django model in one request
I have a User model, UserProfile model. User and UserProfile has one to one relationship. The UserProfile model has some filds like gender, birth_date etc. I need to add another field called profession_info. In this field there are some properties. They are: profession, designation and description. The user can add multiple profession_info. In summary UserProfile has a field called profession_info where a user can add multiple profession related information. What is the best way to accomplish the task. And what is the easiest and effficient way to update the user's profile. I am uising django rest_framework. Can anyone assist me? Thanks in advanced. -
Splitting a blog body content into different sectors in Django
I'm trying to split the contents of my blog into different sections. I don't know what logic to use so that I can't have an image between text sections. I don't want to create a foreign key for the body as my models would get very complex and messy. I don't can't copy my code here because I am asking this question with my mobile phone. I hope you understand my question... I haven't tried anything yet so I will appreciate any idea. -
Failed to load module script: Expected a JavaScript module script but the server responded with a MIME type of "application/octet-stream"
I an getting this error Failed to load module script: Expected a JavaScript module script but the server responded with a MIME type of "application/octet-stream". Strict MIME type checking is enforced for module scripts per HTML spec. on my browser console when trying to run my react/django application. Here's my index.html file; INDEX.HTML {% load static %} <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <link rel="icon" type="image/svg+xml" href="/vite.svg" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <title>BlogHost</title> </head> <body> <div id="root"></div> <script type="module" src="{% static 'main.jsx' %}"></script> </body> </html> I tried using react-django-templatetags. {% load static %} <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <link rel="icon" type="image/svg+xml" href="/vite.svg" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <title>BlogHost</title> </head> <body> <div id="root"></div> {% react_render component='main.jsx' %} </body> </html> Yet, I still get a blank page and an error in my console. -
how to store files into mongodb using django without gridfs?
I am new to working with mongodb and django. I need to know how to stores files into mongodb with the help of django, using the djongo engine. Can anyone help me? I tried using FileField() and setting up the url path. there was no errors yet i couldn't find the file in the db -
How to make a web app running on a local server secure?
I wish to create an app using Django, which users can use on their respective local networks. I want to make this secure, and I have trouble finding a way. Most answers point to using self-signed certificates on the server followed by installing certificates on each individual device on the network. However, this might be complicated and too much effort for the users, who may not be so tech savvy. Is there a simpler, cleaner way of making this app secure within the local network? Something I can automate as well. -
Django application static file getting loaded for localhost but not for 0.0.0.0
I have a django application that I am trying to run on port 0.0.0.0 but the static files are using https (I have SECURE_SSL_REDIRECT=False), the first page is loading without static files but even if I go to the next page it is forwarding to https. I ran the same application on localhost and everything works fine. STATIC_ROOT = os.path.join(SITE_ROOT, 'static/') STATIC_URL = '/static/' MIDDLEWARE = [ # 'corsheaders.middleware.CorsMiddleware', 'django.middleware.security.SecurityMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.common.CommonMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware', ] I have cleared the browser cache multiple times and have checked every possible stackoverflow answer, dont know why this is happening. Please help. + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT) For frontend I am using react js and python version is 3.7.16. Thanks. -
IntegrityError in Django Custom User Model which doesn't go away even after deleting all migrations
I keep getting this error whenever I tried to create a post. I have gone through all similar questions on this platform and made several adjustments but the error still occurs. IntegrityError at /api/admin/create/ NOT NULL constraint failed: blog_post.author_id Request Method: POST Request URL: http://127.0.0.1:8000/api/admin/create/ Below is my cusstom user model: class NewUser(PermissionsMixin, AbstractBaseUser): email = models.EmailField(_('email_address'), unique=True) user_name = models.CharField(max_length=150, unique=True) first_name= models.CharField(max_length=150, blank=True) about = models.TextField(_('about'), max_length=500, blank=True) start_date = models.DateTimeField(default=timezone.now) is_active = models.BooleanField(default=True) is_staff = models.BooleanField(default=True) objects = CustomAccountManager() USERNAME_FIELD = 'email' REQUIRED_FIELDS = ['first_name', 'user_name'] Below is my custom manager for the custome user model: class CustomAccountManager(BaseUserManager): def create_superuser(self, email, user_name, first_name, password, **other_fields): other_fields.setdefault('is_superuser', True) other_fields.setdefault('is_staff', True) other_fields.setdefault('is_active', True) if other_fields.get('is_superuser') is not True: raise ValueError('superuser must be assigned to is_superuser=True') if other_fields.get('is_staff') is not True: raise ValueError('superuser must be assigned to is_staff=True') user = self.create_user(email, user_name, first_name, password, **other_fields) user.save(using=self._db) return user def create_user(self, email, user_name, first_name, password, **other_fields): if not email: raise ValueError(_('You must provide an email address')) email = self.normalize_email(email) user = self.model(email=email, user_name=user_name, first_name=first_name, **other_fields) user.set_password(password) user.save() return user Below is my serializer class for the custome user model: class RegisterUserSerializer(serializers.ModelSerializer): email = serializers.EmailField(required=True) username = serializers.CharField(required=True) password = serializers.CharField(min_length=8, write_only=True) … -
Once python script run completed how to send created log files results to outlook mail using python
I'm very to new to this python and some other technologies, can someone suggest better ideas here very appreciated! I have two python scripts when i ran both scripts, i'm able to create log files with timestamp every time i ran so that log files i need to send outlook mail automatically once my python scripts completed once i ran scripts when it completes i need to send outlook mail with attachment of log files automatically i heard about smptplib library to send mails, but i need to send mail with log files once task completed please suggest your ideas here -
Issue with Loading HTML Template After Sending Email in Django
I'm working on a Django project where I need to send an email after a form submission. I have implemented the email sending functionality using the smtplib module. The email is sent successfully, but after that, I'm unable to load the corresponding HTML template (delivery_email_success.html). Here's the relevant code in my view: def enviar_email(request): if request.method == 'POST': # Process data and prepare the email try: # Email setup and sending # ... server.quit() except smtplib.SMTPException as e: return render(request, 's3_error.html') print('Now rendering the success') return render(request, 'delivery_email_success.html') else: return HttpResponse(status=405) And here's the HTML part that submits the form and calls this function: const emailForm = document.getElementById('email-form'); emailForm.addEventListener('submit', (event) => { event.preventDefault(); const visibleRows = document.querySelectorAll('.result-row'); const data = []; visibleRows.forEach(row => { const rowData = { title: row.querySelector('td:nth-child(2)').textContent, catalog: row.querySelector('td:nth-child(3)').textContent, folder: row.querySelector('td:nth-child(4)').textContent, assets: row.querySelector('td:nth-child(5)').textContent, package: row.querySelector('td:nth-child(6)').textContent, sk: row.querySelector('td:nth-child(7)').textContent }; data.push(rowData); }); const emailBody = tinymce.activeEditor.getContent({ format: 'html' }); const formData = new FormData(); formData.append('email_body', emailBody); formData.append('data', JSON.stringify(data)); const csrfToken = document.querySelector('input[name="csrfmiddlewaretoken"]').value; formData.append('csrfmiddlewaretoken', csrfToken); fetch("{% url 'email_delivery' %}", { method: 'POST', body: formData }) .then(response => response.json()) .then(result => { // Manejar la respuesta del servidor }) .catch(error => { // Manejar errores }); }); I have verified that … -
How to pass Ajax POST request with GeoJSON or simply JSON data in Django view?
I am learning how to use jQuery Ajax and how to combine it with my Django project. My Django template comes with a JS source that adds a Leaflet EasyButton to my map with an Ajax POST request to pass some JSON data that is then processed on the Django side: // Create a button to process Geoman features var btn_process_geoman_layers = L.easyButton('<img src="' + placeholder + '" height="24px" width="24px"/>', function (btn, map) { var csrftoken = jQuery("[name=csrfmiddlewaretoken]").val(); function csrfSafeMethod(method) { return (/^(GET|HEAD|OPTIONS|TRACE)$/.test(method)); } $.ajaxSetup({ beforeSend: function (xhr, settings) { if (!csrfSafeMethod(settings.type) && !this.crossDomain) { xhr.setRequestHeader("X-CSRFToken", csrftoken); } } }); // Retrieve all Geoman layers var geoman_layers = map.pm.getGeomanLayers(true).toGeoJSON(); // Process only layers that are feature collections if (geoman_layers["type"] === "FeatureCollection") { // For every feature (e.g. marker, polyline, polygon, circle) for (feature_idx in geoman_layers["features"]) { var feature = geoman_layers["features"][feature_idx]; // pass the feature using Ajax to Django switch(feature["geometry"]["type"]) { case "Polygon": console.log("Polygon"); $.ajax({ url: "", data: { "feature": feature }, datatype: "json", type: "POST", success: function (res, status) { //alert(res); alert(status); }, error: function (res) { alert(res.status); } }); break; default: console.log("Other feature: " + feature["geometry"]["type"]); break; } } } }); btn_process_geoman_layers.addTo(map).setPosition("bottomright"); Currently the data is all features of … -
Django - Includes with blocks inside?
How would you go about creating an include which takes HTML such as templates with blocks? The idea being to pass some blocks into a reusable component e.g. {% include 'banner.html' %} {% block text %} Christmas Sale! {% endblock %} {% block bodyCopy %} When checking out apply the <underline>discount</underline> code <span>F5000</span>! {% endblock %} {% end include %} This would allow you included component to take these different blocks and render as expected e.g. <header> <h1>{% block text $}</h1> <div> <p> {% block bodyCopy %} </p> </div> </header> Symfony has a similar concept called "embeds" -> https://twig.symfony.com/doc/2.x/tags/embed.html -
Could not connect to ws://127.0.0.1:8000/ using django channels
I was trying to make a websocket connection using django channels. gs1 is my project name and app is an app inside the project When I run python manage.py runserver and type ws://127.0.0.1:8000/ws/sc/ in postman and press connect I am getting "Could not connect to ws://127.0.0.1:8000/ws/sc/" error in postman and "Not Found: /ws/sc/" error in the backend. These are the modifications I made in my settings.py file : INSTALLED_APPS = [ 'channels', 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'app', ] ASGI_APPLICATION = 'gs1.asgi.application' WSGI_APPLICATION = 'gs1.wsgi.application' This is my asgi.py file : import os from django.core.asgi import get_asgi_application from channels.routing import ProtocolTypeRouter, URLRouter import app.routing os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'gs1.settings') application = ProtocolTypeRouter({ 'http': get_asgi_application(), 'websocket': URLRouter( app.routing.websocket_urlpatterns ), }) This is my routing.py file : from django.urls import re_path from . import consumers websocket_urlpatterns = [ re_path('ws/sc/', consumers.MySyncConsumer.as_asgi()), re_path('ws/ac/', consumers.MyAsyncConsumer.as_asgi()), ] This is my consumers.py file : from channels.consumer import SyncConsumer, AsyncConsumer class MySyncConsumer(SyncConsumer): def websocket_connect(self, event): print("Websocket connected....") def websocket_receive(self, event): print("Message Received....") def websocket_disconnect(self, event): print("Websocket disconnected....") class MyAsyncConsumer(AsyncConsumer): async def websocket_connect(self, event): print("Websocket connected....") async def websocket_receive(self, event): print("Message Received....") async def websocket_disconnect(self, event): print("Websocket disconnected....") -
Issue with connecting postgresql in django
i made a project on django. i work in virtualenv, i installed psycopg2-binary, tried to connect postgresql instead of sqlite3. rewrite code in settings.py DATABASES = { 'default': { 'ENGINE': 'django.db.backends.postgresql', 'NAME': 'database', 'USER': 'user', 'PASSWORD': 'mypassword', 'HOST': 'localhost', 'PORT': '5432', } } and when enter python manage.py runserver, i get this Watching for file changes with StatReloader Performing system checks... conn = _connect(dsn, connection_factory=connection_factory, **kwasync) psycopg2.OperationalError: connection to server at "localhost" (127.0.0.1), port 5432 failed: FATAL: password authentication failed for user "user" connection to server at "localhost" (127.0.0.1), port 5432 failed: FATAL: password authentication failed for user "user" The above exception was the direct cause of the following exception: Traceback (most recent call last): File "/usr/lib/python3.10/threading.py", line 1016, in _bootstrap_inner self.run() File "/usr/lib/python3.10/threading.py", line 953, in run self._target(*self._args, **self._kwargs) File "/home/user/Desktop/project/venv/lib/python3.10/site-packages/django/utils/autoreload.py", line 64, in wrapper fn(*args, **kwargs) File "/home/user/Desktop/project/venv/lib/python3.10/site-packages/django/core/management/commands/runserver.py", line 136, in inner_run self.check_migrations() File "/home/user/Desktop/project/venv/lib/python3.10/site-packages/django/core/management/base.py", line 574, in check_migrations executor = MigrationExecutor(connections[DEFAULT_DB_ALIAS]) File "/home/user/Desktop/project/venv/lib/python3.10/site-packages/django/db/migrations/executor.py", line 18, in __init__ self.loader = MigrationLoader(self.connection) File "/home/user/Desktop/project/venv/lib/python3.10/site-packages/django/db/migrations/loader.py", line 58, in __init__ self.build_graph() File "/home/user/Desktop/project/venv/lib/python3.10/site-packages/django/db/migrations/loader.py", line 235, in build_graph self.applied_migrations = recorder.applied_migrations() File "/home/user/Desktop/project/venv/lib/python3.10/site-packages/django/db/migrations/recorder.py", line 81, in applied_migrations if self.has_table(): File "/home/user/Desktop/project/venv/lib/python3.10/site-packages/django/db/migrations/recorder.py", line 57, in has_table with self.connection.cursor() as cursor: File "/home/user/Desktop/project/venv/lib/python3.10/site-packages/django/utils/asyncio.py", line … -
POST http://127.0.0.1:8000/customRegisterForm/UploadImageViewSet/ 415 (Unsupported Media Type)
While Posting the image from react JS using fetch operation getting the error 415 (Unsupported Media Type) and for backend used django Error in console: enter image description here Here is React JS code: UploadImages.js `import React from "react" export default function UploadImages() { const [picture, setPicture] = React.useState({}) function data(event) { setPicture((prevPicture) => { return { ...prevPicture, [event.target.name]: [event.target.value] } }) } console.log(picture) function handleChange(event) { event.preventDefault() fetch("http://127.0.0.1:8000/customRegisterForm/UploadImageViewSet/", { method: "POST", body: JSON.stringify({ upload_name: picture.upload_name, image_upload: picture.image_upload, }), header: { "Content-Type": "application/json" }, }); } return ( <div> <form onSubmit={handleChange}> Name: <input type="text" name="picture.upload_name" onChange={data} placeholder="Name" value={picture.upload_name} /><br /> <input type="file" name="picture.image_upload" onChange={data} accept="image/jpeg, image/png" value={picture.image_upload} /><br /> <button>Submit</button> </form> </div> ) } ` Models.py `class UploadImage(models.Model): upload_name = models.TextField(max_length=50, blank=False) image_upload = models.ImageField(upload_to="UserUploadImage/", blank=True, null=True) Serializers.py class UploadImageSerializer(serializers.ModelSerializer): class Meta: model = UploadImage fields = ('id', 'upload_name', 'image_upload') ` Url.py router.register("UploadImageViewSet", UploadImageViewSet) Views.py class UploadImageViewSet(viewsets.ModelViewSet): queryset = UploadImage.objects.all() serializer_class = UploadImageSerializer I tried all the possibilities but did not got solution, please help to get solution. Thanks! Need solution for POST http://127.0.0.1:8000/customRegisterForm/UploadImageViewSet/ 415 (Unsupported Media Type) -
Django rest api and axios post request doesn't add new instance
am trying to make a simple api where a user writes something in a field, presses a button and a new instance is added in the database. To do this I am using react and django rest framework. App.js const [name,setName] = useState('') const handleChange = (e) => { setName(e.target.value) } function handleClick(e) { axios.defaults.xsrfCookieName = 'csrftoken' axios.defaults.xsrfHeaderName = "X-CSRFTOKEN" axios.post('http://127.0.0.1:8000/post/', { headers: { "Content-Type": "application/x-www-form-urlencoded", 'X-CSRFToken': 'csrftoken' }, data:{ title: name, name: name } }) } return ( <> <form> <input type='text' value={name} onChange={handleChange} /> <button onClick={handleClick}>OK</button> </form> </> ); views.py @api_view(['POST']) def home2(request): serializer = ItemSerializer(data=request.data) if serializer.is_valid(): serializer.save() return Response(serializer.data) urls.py from django.urls import path from . import views urlpatterns = [ path('api/',views.home,name='home'), path('post/',views.home2,name='home2'), path('a/',views.home3,name='home3') ] settings.py INSTALLED_APPS = [ 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'rest_framework', 'main', 'corsheaders' ] CORS_ORIGIN_ALLOW_ALL = True CORS_ALLOW_CREDENTIALS = True But when I press the button I get manifest.json:1 GET http://127.0.0.1:8000/manifest.json 404 (Not Found) and manifest.json:1 Manifest: Line: 1, column: 1, Syntax error. in javascript. In django I get "POST /post/ HTTP/1.1" 200 0 Also I am using npm run build for javascript and manifest.json is in public folder. React is inside django and the structure looks like this: mysite frontend … -
Django 4.2 : `receiver` Decorator Does Not Receive Signal
I am experimenting with Django Signals. In the documentation, it is written that there are two ways to connect a receiver to a signal. Using Signal.connect method Using receiver decorator Here's what I have implemented: # models.py from django.db import models from django.dispatch import receiver from .signals import demo_signal class Demo(models.Model): demo = models.CharField("demo", max_length=50) def send_signal(self): demo_signal.send(self) print('signal sent') def connect_receiver(self): demo_signal.connect(signal_handler, sender=self) @receiver(demo_signal, sender=Demo) def signal_handler(**kwargs): print('signal handled') # signals.py from django.dispatch import Signal demo_signal = Signal() However, when I call send_signal method, I don't get signal handled printed out unless I call connect_receiver method first. In [1]: demo = Demo.objects.get(pk=2) In [2]: demo Out[2]: <Demo: Demo object (2)> In [3]: demo.send_signal() signal sent In [4]: And Interestingly enough, after implementing pre_delete_handler as follows, without connecting, calling delete method does call pre_delete_handler @receiver(pre_delete, sender=Demo) def pre_delete_handler(instance, **kwargs): print(instance, kwargs) print('pre delete') Receiver does receive the signal without sender argument: @receiver(pre_delete) def pre_delete_handler(instance, **kwargs): print(instance, kwargs) print('pre delete') But how can I make it listen to a specific Model? Why does sending signal does not call its receiver(decorated signal_handler) in my case? -
How to configure APscheduler to use it with django_tenants
I am using django and django rest framework with multi teancy system. For multitenancy I am using django_tenants package, If I add "apscheduler" to TENANT_APPS and run migrate_schemas command I get this error Error getting due jobs from job store 'default': relation "rest_apscheduler_djangojob" does not exist LINE 1: ...d", "rest_apscheduler_djangojob"."job_state" FROM "rest_apsc... -
In Azure i wanto run a worker like heroku
Previously I have hosted my web application in heroku there I have two dyno in procflie i have this two line of code web: gunicorn project.wsgi worker: python manage.py fetch_data worker is custom script that fetch data and store it in postgresql.. i can run scrip locally and push data in azure from local pc but i want to host this in azure like heroku where custom script named fech_data works automatically. many tutorial says about webjob. but there is no webjob option in my web application. it is hosted in linux environment. -
Sending Email via Django Backend for forgeting Password
Hello I'm working with Django for sending Email for forgeting password. I'm trying to use Django class based views to handle this forget password but, It was not worked properly. here is my code : settings.py EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend' EMAIL_HOST = 'smtp.gmail.com' EMAIL_USE_SSL = False EMAIL_USE_TLS = True EMAIL_PORT = 587 EMAIL_HOST_USER = config("EHU") # set my email EMAIL_HOST_PASSWORD =config("EHP") # set my app password views.py from django.urls import reverse_lazy from django.views.generic import FormView from django.contrib.auth.views import ( LoginView, LogoutView, PasswordResetView, PasswordResetConfirmView, PasswordResetCompleteView ) from .models import UserAccount from .forms import RegisterForm class LoginPageView(LoginView): template_name = "login.html" def get(self, request, *args, **kwargs): if request.user.is_authenticated: return reverse_lazy("/") return super().get(request, *args, **kwargs) class LogoutPageView(LogoutView): template_name = "logout.html" class SignupPageView(FormView): template_name = "register.html" form_class = RegisterForm success_url = reverse_lazy("/") def get(self, request, *args, **kwargs): if request.user.is_authenticated: return reverse_lazy("/") return super().get(request, *args, **kwargs) def form_valid(self, form): new_user = UserAccount.objects.create_user( email=form.cleaned_data['email'], username=form.cleaned_data['username'], password=form.cleaned_data['password'], first_name=form.cleaned_data['first_name'], last_name=form.cleaned_data['last_name'], pic=form.cleaned_data['pic'], description=form.cleaned_data['description'], # TODO : If you add other fields to your model, include them here ) return super().form_valid(form) class PasswordChangePageView(PasswordResetView): template_name ="pass_change.html" email_template_name = "pass_change_email.html" subject_template_name = "password_reset_subject.txt" success_message =""" We've emailed you instructions for setting your password, if an account exists with the email you entered. You should … -
how to implement foreign key popup to add django admin panel functionality on django app
I want implement popup to add like django admin panel in my django app. please guide me. -
Redis connection scheduled to be closed ASAP for overcoming of output buffer limits
I have some celery tasks that run on VMs to run some web crawling tasks. Python 3.6, Celery 4.2.1 with broker as Redis (self-managed). The same Redis server is used for caching and locks. There are two relevant tasks: 1. job_executor: This celery worker runs on a VM and listens to the queue crawl_job_{job_id}. This worker will execute the web crawling tasks. Only a single job_executor worker with concurrency = 1 runs on 1 VM. Each Crawl Job can have 1-20,000 URLs. Each Crawl Job can have anywhere between 1 to 100 VMs running in a GCP Managed Instance Group. The number of VMs to be run are defined in a configuration for each crawl job. Each task can take from 15 seconds to 120 minutes. 2. crawl_job_initiator: This celery worker runs on a separate VM and listens to the queue crawl_job_initiator_queue. One task creates the required MIG and the VMs using terraform for a single Crawl Job ID and adds the job_executor tasks to the crawl_job_{job_id} queue. The task takes about 70 seconds to complete. The concurrency for this worker was set to 1 so only 1 Crawl Job could be started at once. To reduce the time it … -
Django project ModuleNotFoundError: No module named '_sqlite3'
OS bsd 13.2 on dedicated rental server csh terminal python3.9.17 system and venv Django 4.2.2 wanting to learn django, I set up a venv and installed django there. all good but at (django) pyweb@os3-286-32838:~/django/eigoweb % python3 manage.py runserver things seem to be loading but it stalls at the end with... File "/usr/local/lib/python3.9/importlib/init.py", line 127, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "/home/pyweb/django/lib/python3.9/site-packages/django/db/backends/sqlite3/base.py", line 9, in from sqlite3 import dbapi2 as Database File "/usr/local/lib/python3.9/sqlite3/init.py", line 57, in from sqlite3.dbapi2 import * File "/usr/local/lib/python3.9/sqlite3/dbapi2.py", line 27, in from _sqlite3 import * ModuleNotFoundError: No module named '_sqlite3' while the venv is activated I tried to import sqlite3 from python3 import sqlite3 Traceback (most recent call last): File "", line 1, in File "/usr/local/lib/python3.9/sqlite3/init.py", line 57, in from sqlite3.dbapi2 import * File "/usr/local/lib/python3.9/sqlite3/dbapi2.py", line 27, in from _sqlite3 import * ModuleNotFoundError: No module named '_sqlite3' I get the same message with the system python. so.. the module is not there it seems After reading several posts here I added PYTHONPATH in the venv to where there appeared to be sqlite3 module but it was not _sqlite3 so I guess that is the problem? pyweb@os3-286-32838:~/django/lib/python3.9/site-packages % ls Django-4.2.2.dist-info dbrelmgr.py pycache distutils-precedence.pth _distutils_hack django antiorm-1.2.1.dist-info pip … -
how to write select_for_update test?
def db_lock_on_resource(self, resource_id): list(Models.objects.select_for_update().filter(id=resource_id)) I have this storage function call and I want to write a test for it using Py-Test. How can I write it? What should I assert?