Django community: RSS
This page, updated regularly, aggregates Django Q&A from the Django community.
-
Django not showing variables
I am starting on my journey with Django but have hit a problem with it showing variables. In principle I want a list of buildings from which I have a Home page that shows a list of all of them as links that take you to an page that shows the detail of each one. in models.py I have: class Build(models.Model): building_name = models.CharField( max_length=50) address = models.CharField(max_length = 100) #other details in views.py I have: from django.shortcuts import render from django.shortcuts import get_object_or_404 from django.http import HttpResponse from .models import Build def home(request): builds = Build.objects.all() return render(request, 'Home.html', {'builds':builds,}) def building_detail(request,build_id): #return HttpResponse(f'<p> building number {build_id}</p>') build = get_object_or_404(Build, id=build_id), return render(request, 'Building_detail.html', {'build':build,}) In URLs.py I have: from django.contrib import admin from django.urls import path from Buildings import views urlpatterns.py = [ path('admin/', admin.site.urls), path('', views.home, name='home'), path('buildings/<int:build_id>/', views.building_detail, name= 'building_detail'), ] For the Home.html file I have: <p>Home view from template</p> <div> {% for build in builds %} <div class="buildingname"> <a href="{% url 'building_detail' build.id %}"> <h3>{{build.building_name|capfirst}}</h3> </a> </div> {% endfor %} </div> and for Building_detail.html this <div> <h3>{{build.building_name|capfirst}}</h3> <p>building view from template is this working</p> <h3>does this {{build.building_name|capfirst}} work</h3> <p>{{build.address}} </div> the Home page works … -
Cannot import the include() in Django
I'm trying the django tutorial, but when doing it it gives me this error: File "/home/mariorich/dev/django-tutorial/mysite/mysite/urls.py", line 22, in path('polls', include('polls.url') ) ^^^^^^^ NameError: name 'include' is not defined I also have this other problems in my VSCode: VSCode Problems I'm working in a vitural environment, and when checking the django version: (django-tutorial) mariorich@mario-laptop:~/dev/django-tutorial/mysite$ python -m django --version 5.0 So I think that the package is well installed. this is my urls.py: from django.contrib import admin from django.urls import include, path urlpatterns = [ path("polls/", include("polls.urls")), path("admin/", admin.site.urls), ] Can you help me please? For reference, when I ran the server the first time, without this path, It was all working fine with the django default page "django was sucessfuly installed". I'm working in Linux. Thank you I already tried to kill the terminal and run the code again, but I don't know what to do more as I'm still a begginer. -
I am unable to find frontend of react-django app, it is already build and I want to customize it?
I have a website project on my local host that is built on react frontend and django backend. I want to edit thr frontend (react) but I am unable to find the components, how can I edit and find the frontend components? I want to find the answer of my problem the best possible solution. -
makemigrations in Django (under docker-compose) doesn't stored files of migrations, but performs database changes
Today my colleague suggested deleting the migration files in order to create them again. When I went to this action, I saw that in my application's migrations folder there was only init.py At the same time, the actions necessary with the database (in particular, the creation of additional tables for models) were previously performed. I'm working at this project about week, and performed commands below more than one time, sure! But never saw that no any files stored into migrations folder. This is my command to run makemigrations: docker-compose exec web python manage.py makemigrations This is the command to perform migrations: docker-compose exec web python manage.py migrate --noinput This is my docker-compose.yml: version: '3' services: web: build: context: . dockerfile: Dockerfile restart: always volumes: - ./static/:/app/static/ - ./media/:/app/media/ command: > sh -c "gunicorn conf.wsgi:application --bind 0:8000" depends_on: - db ports: - "8000:8000" env_file: - .env environment: - DEBUG=True logging: driver: "json-file" options: max-size: "10m" max-file: "3" db: image: postgres:latest environment: POSTGRES_DB: $DB_NAME POSTGRES_USER: $DB_USER POSTGRES_PASSWORD: $DB_PASS pgadmin: container_name: pgadmin image: dpage/pgadmin4 environment: PGADMIN_DEFAULT_EMAIL: pgadmin4@pgadmin.org PGADMIN_DEFAULT_PASSWORD: postgres ports: - "5050:80" volumes: postgres_data: static_volume: ssl_volume: I tried to restart containers, docker. Restarted IDE (PyCharm) some times also. -
Docker django, nginx, uwsgi
I have been breaking my head for past few days trying to get django, nginx, and uwsgi working on docker. I have looked through 100's of tutorials on this, and none of them seem to work for me, I'm probably doing something wrong, but can't figure out what. I have a simple django app, that i want to dockerize. Does anyone have any good tutorial or simple step by step procedure on setting up a docker for django, that i can just upload any django app to and it will work, ofcourse with editing the nginx and uwsgi configs. -
Gunicorn sync worker and threads
I am running a Gunicorn server with 2 'sync' workers. When i run htop --filter gunicorn, i get 2 worker entries as expected. htop But, when i press H to show number of threads, it shows a lot of entries. htop -H(https://i.stack.imgur.com/Ng2l7.jpg) I am running in hyper-threading enabled cpu with 8 physical cores. why are there so many entries after pressing H? Ideally a sync worker only has single thread, so should there be 2 threads only. Am i missing something? Please help me resolve this confusion -
How to attach files with celery args
I have been facing problem regarding how to attach the file in the celery args. I am creating an email schedule functionality in my website where I am using django-celery-beat to do this. However, the file is OfCourse user uploaded, and optional, and for the args in PeriodicTask model of django-celery-beat, I can't really get the file to be sent along with the email. this is the function (not in views.py) defsend_scheduled_email(to_email_list_final,cc_email_list_final,bcc_email_list_final,subject,mail_body,email_schedule_date_time,attachment=None): scheduled_email_date_time = datetime.strptime(email_schedule_date_time, '%Y-%m-%dT%H:%M') unique_task_name = f"{subject}_{scheduled_email_date_time.timestamp()}" PeriodicTask.objects.create( clocked = ClockedSchedule.objects.get_or_create(clocked_time=scheduled_email_date_time)[0], name=unique_task_name , task = "public_relation_team.tasks.send_scheduled_email", args =json.dumps([to_email_list_json,cc_email_list_json,bcc_email_list_json,subject,mail_body,attachment]), one_off = True, enabled = True, ) And this is in tasks.py @shared_task def send_scheduled_email(to_email_list, cc_email_list, bcc_email_list, subject, mail_body, attachment): PRT_Email_System.send_email(to_email_list, cc_email_list, bcc_email_list, subject, mail_body,attachment) For emails without being scheduled, i.e that can be send directly I have used file attachment system and faced no problem with it This is the function, def send_email_confirmation(to_email_list_final,cc_email_list_final,bcc_email_list_final,subject,mail_body,attachment): email_from = settings.EMAIL_HOST_USER if attachment is None: try: email=EmailMultiAlternatives(subject,mail_body, email_from, to_email_list_final, bcc=bcc_email_list_final, cc=cc_email_list_final ) email.send() return True except Exception as e: print(e) return False else: try: #Create a ContentFile from the uploaded file content_file = ContentFile(attachment.read()) content_file.name = attachment.name # Set the filename email=EmailMultiAlternatives(subject,mail_body, email_from, to_email_list_final, bcc=bcc_email_list_final, cc=cc_email_list_final ) email.attach(attachment.name,content_file.read(),attachment.content_type) email.send() return True except Exception as … -
Django dynamic URL pattern returns 404
I'm currently building a Django CMS App. When I try to use dynamic url patterns, I get only 404. Debug = True returns: Using the URLconf defined in myproject.urls, Django tried these URL patterns, in this order: [...] ro/ gallery/int:folder_pk/ [name='dynamic_gallery_view'] [...] The current path, /ro/gallery/3/, didn’t match any of these. urls.py from django.urls import path from .views import (postBarbersCards_create_employee, postBarbersCards_create_location, postBarbersCards_update_employee, postBarbersCards_update_location, postBarbersCards_delete_employee, postBarbersCards_delete_location, postBarbersCards_caroussel, render_gallery_location, render_gallery_location_selector) urlpatterns = [ # ... other urls path('post/ajax/postBarbersCards_create_employee', postBarbersCards_create_employee, name = "postBarbersCards_create_employee"), path('post/ajax/postBarbersCards_create_location', postBarbersCards_create_location, name = "postBarbersCards_create_location"), path('post/ajax/postBarbersCards_update_employee', postBarbersCards_update_employee, name = "postBarbersCards_update_employee"), path('post/ajax/postBarbersCards_update_location', postBarbersCards_update_location, name = "postBarbersCards_update_location"), path('post/ajax/postBarbersCards_delete_employee', postBarbersCards_delete_employee, name = "postBarbersCards_delete_employee"), path('post/ajax/postBarbersCards_delete_location', postBarbersCards_delete_location, name = "postBarbersCards_delete_location"), path('post/ajax/postBarbersCards_caroussel', postBarbersCards_caroussel, name = "postBarbersCards_caroussel"), path('gallery/<int:folder_pk>/',render_gallery_location, name='dynamic_gallery_view'), path('gallery/location',render_gallery_location_selector, name='dynamic_gallery_location_view'), # ... ] views.py from django.shortcuts import get_object_or_404, render from django.http import JsonResponse from django.core import serializers from django.http import HttpResponse from .models import Barbers_Locations_Model, Barbers_Employees_Model from filer.models.filemodels import File from filer.models.foldermodels import Folder import json [...] def render_gallery_location(request, folder_pk): item = File.objects.filter(folder_id=folder_pk).values('file', 'folder_id') return render(request, '_barbers_cards_gallery_page.html', {'item': item }) I tested everything beforehand on my DEV server and it worked with the build in Django webserver. Now, when I try to go into production, it seems broken. What do I do wrong? -
Sending data from client-side to server-side in django [duplicate]
I want to make a shopping cart system for my Django project. CLients should make a shopping cart in their side and then passed that to server side.but when I send data now I get this error please help me.Invalid request: Missing required parameters this is my client-side code <!DOCTYPE html> <html> <head> <script src="https://code.jquery.com/jquery-3.6.4.min.js"></script> <title>Items</title> </head> <body> <a href="{% url 'dashboard' %}">Home</a> {% for cloth in clothes %} <li> <input type="hidden" name="csrfmiddlewaretoken" value="{% csrf_token %}"/> <strong>{{ cloth.name }}</strong> - {{ cloth.description }} - {{ cloth.price }} {% if cloth.profile_picture %} <img src="{{ cloth.profile_picture.url }}" width="100"> {% else %} <p>No image available</p> {% endif %} <!-- Add to Cart form for each cloth item --> <form class="add-to-cart-form" data-product-id="{{ cloth.id }}" data-product-name="{{ cloth.name }}" data-product-price="{{ cloth.price }}"> {% csrf_token %} <label for="quantity{{ cloth.id }}">Quantity:</label> <input type="number" id="quantity{{ cloth.id }}" min="0" value="1"> <button type="button" class="add-to-cart-button">Add to Cart</button> </form> </li> {% endfor %} <script> function getCookie(name) { let cookieValue = null; if (document.cookie && document.cookie !== '') { const cookies = document.cookie.split(';'); for (let i = 0; i < cookies.length; i++) { const cookie = cookies[i].trim(); // Does this cookie string begin with the name we want? if (cookie.substring(0, name.length + 1) === … -
Get Selected value from Model Choice Field before Submission - Django
Good Morning for all ! I´ve researched many time how to do but not got it. I need to retrieve the value off Model Choice Field before submit it to show a diferent Modal Forms to the user fill it. Next see my codes. I this case, the field is status I wiil appreciate so much your assistence. Thank you ! Models.py from django.db import models FISICA = 1 JURIDICA = 2 CLIENTE_STATUS = ( ('', 'Tipo'), ('FISICA', 'Física'), ('JURIDICA', 'Jurídica'), ) class Cliente(models.Model): nome = models.CharField(max_length=30) idade = models.IntegerField(blank=True, null=True) status = models.CharField(max_length=10, null=True, choices=CLIENTE_STATUS) Views.py from django.shortcuts import render from django.urls import reverse_lazy from exemplo.forms import ClienteForm from exemplo.models import Cliente from django.views.generic import ListView, CreateView, UpdateView, DetailView, DeleteView class ClienteList(ListView): model = Cliente queryset = Cliente.objects.all() class ClienteCreate(CreateView): model = Cliente fields = '__all__' success_url = reverse_lazy('exemplo:list') class ClienteUpdate(UpdateView): model = Cliente fields = '__all__' success_url = reverse_lazy('exemplo:list') class ClienteDetail(DetailView): queryset = Cliente.objects.all() class ClienteDelete(DeleteView): queryset = Cliente.objects.all() success_url = reverse_lazy('exemplo:list') Forms.py from django import forms from django.shortcuts import render from exemplo.models import Cliente class ClienteForm(forms.ModelForm): class Meta: model = Cliente fields = '__all__' cliente_form.html <!DOCTYPE html> <html lang="pt-br"> <head> <meta charset="UTF-8"> <title>Criar Cliente</title> </head> <body> <h1>Cadastro … -
"ImportError: cannot import name 'Sequence' from 'collections'" - Azure Linux web app with Python and Django
I have a Django app that I am deploying as a Azure linux web app. It has been running fine for months but now on startup after deployment via AzDO CI/CD pipeline it errors with from collections import Sequence at line 10 when loading pathlib.py from the MS version in the docker container. The official version of pathlib.py (https://github.com/python/cpython/blob/3.12/Lib/pathlib.py) reads from _collections_abc import Sequence See docs at https://docs.python.org/3/library/pathlib.html This is a known problem and is resolved by moving from the MS version to the later official version. The issue is that this problem is in the MS distro and not in my code or even the version of the library that gets installed with pip. Even if you change it, any deployment over-writes the correct version with the version in the MS distro. The app works fine locally with the official pathlib.py and previously worked OK on Azure. It looks like a regression error with the library being used. I have tried editing the Azure version of pathlib.py but it gets over-written on every [container] restart or redeployment. How can I change the version of pathlib.py being used by Azure or otherwise work-around this please? -
Django application on Docker is starting up but browser gives empty response and localhost doesn't send any data
I have created a simple app with Django, Python3, and Docker on Windows: Dockerfile FROM python:3.7.6 ENV PYTHONUNBUFFERED 1 RUN mkdir /code WORKDIR /code COPY requirements.txt /code/ RUN pip install -r requirements.txt COPY . /code/ docker-compose.yml version: '3.2.22' services: analyzer: build: context: ./analyser command: bash -c "python ./analyser/manage.py migrate && python ./analyser/manage.py runserver 8000" volumes: - .:/code ports: - "8000:8000" restart: always In my case, I don't need a DB. So I haven't added the details of it and 'depends_on'. I have read a few similar questions like this which says check the filename. My file names are 'Dockerfile' and 'docker-compose.yml'. I think I don't have any issues with filenames. I have tried like this 'python ./analyser/manage.py runserver 0.0.0.0:8000' But that also dosn't seem to works Looks like the Docker is starting but from my browser, I get this response [+] Building 0.0s (0/0) docker:default [+] Running 1/1 ✔ Container version_1-analyser-1 Recreated 0.1s Attaching to version_1-analyser-1 Operations to perform: Apply all migrations: admin, auth, contenttypes, sessions Running migrations: No migrations to apply. Watching for file changes with StatReloader Performing system checks... System check identified no issues (0 silenced). December 18, 2023 - 10:33:49 Django version 3.2.22, using settings 'analyser.settings' Starting … -
Getting the csrftoken in my react app to be used in my Django app
I’m building an app with a React frontend and Django backend. But the issue is I need csrftoken. How do I generate csrftoken in Django when I make an APi call to the endpoint. I have searched but can’t find the solution. I have tried using csrf_exempt which works but I know this is not secure, please help. Thanks -
Django error We're sorry, but something went wrong
I create a project on Dreamhost, using Django on a subdomain jp and it gives me an error "We're sorry, but something went wrong.". The log file doesn't contain anything, it is 0kb. I tried both DEBUG = True and DEBUG = False. I created the project following their instruction: https://help.dreamhost.com/hc/en-us/articles/360002341572-Creating-a-Django-project I created it as usually, the only difference, I created it connected to the database which was used for the original domain, because it is a copy of the website just on another language. Just for your information, maybe this is the reason, I already don't know. On Dreamhost you need to create Django projects with passenger_wsgi.py. This is a passenger_wsgi.py code: import sys, os INTERP = "/home/my_user/jp.naiuma.com/venv/bin/python3" #INTERP is present twice so that the new python interpreter #knows the actual executable path if sys.executable != INTERP: os.execl(INTERP, INTERP, *sys.argv) cwd = os.getcwd() sys.path.append(cwd) sys.path.append(cwd + '/naiuma') #You must add your project here sys.path.insert(0,cwd+'/venv/bin') sys.path.insert(0,cwd+'/venv/lib/python3.12.1/site-packages') os.environ['DJANGO_SETTINGS_MODULE'] = "naiuma.settings" from django.core.wsgi import get_wsgi_application application = get_wsgi_application() The name of the project is naiuma and the version of python is 3.12.1, the name of the user is correct. This is the settings.py code: """ Django settings for naiuma project. Generated by … -
Django - Model too large?
I want to create one large model with 270 model fields, it were originally nested jsons, but when it comes to .filter() it turned out that json paths (e.g. myjsonfoo__0__myjsonkey__gte filter) are pretty pretty slow. So I decided to either split it into 6 models with 1 parent (option 1) or to keep all together inside one model (270 model fields, option 2). What would you suggest me, is it too heavy to manage 270 modelfields? (small production database, postgresql) -
How to have a master detail datatableview/gird in django
I'm developing an application with many tables and my users need to see data as grids and do some operations such add,edit, export , .. . To achieve this, I use django-datatable-view; I'd like to have a master-detail datatableview in my app. I've used MultipleDatatableView according to the document. I'm confused How to edit the front and add a GET parameter hint (exp: ?datatable=master) . Without using MultipleDatatableView, my code works correctly but when I change it to multiple, it doen't work because of this error: django.utils.datastructures.MultiValueDictKeyError: 'datatable' I tried to add datatable=master in the option of datatable, but this doesn't work. The reason I'm using datatableview is that I need a custom library to show complex data in a table with many features such formatter function, exporting , .... If there is better ways in django, I would be delighted to know. -
Failed CSS using Django
I am a beginner and i recently tried to experiment in Django. I was following a tutorial in designing a Django blog but i encountered a problem when I tried to integrate my css. I have tried other various methods even outside the tutorial but I have still been unable to connect the two files. I have tried some of the suggested methods from other posts but they did not resolve the issue html file {% load static %} <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title> Ugandan Engineers </title> <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous"> <link rel="stylesheet" href="{% static 'css/posts.css' %}"> <!-- <link rel="stylesheet" href="base.css"> --> </head> <body> <header class= "page-header"> <div class= "container"> <h1><a href="http://127.0.0.1:8000/">Engineers</a></h1> <a href="{% url 'post_new' %}" class="top-menu"> {% include './icons/file-earmark-plus.svg' %} </a> </div> </header> <main class="container"> <div class="row"> <div class="col"> {% block content %} {% endblock %} </div> </div> </main> </body> </html> css file h1 { color: darkblue; } h2 { color: blueviolet; } body { padding: 20px; width: 100%; height: 100%; } p { color: brown; } .page-header { text-align: center; padding-top: 20px; padding-bottom: 40px; } the css is supposed to center align the text as well as change the color of my h2 … -
Bypass or establish a fixed OTP for a specific email auth0
We are preparing to submit our app for review on the Play Store and App Store. However, we’ve encountered a challenge related to our passwordless email OTP authentication. Specifically, we are seeking guidance on how to bypass or establish a fixed OTP for a specific email, which we can include with our app submission. While transitioning to username-database authentication could address the issue, it’s important to note that this solution would be effective only for the initial release. Subsequent shifts from passwordless authentication back to username-database authentication in later releases might disrupt the existing user experience. Could anyone please assist with this matter? -
How should I appropriately submit a form within a Django application? [closed]
I'm attempting to submit a form in my Django app, but it consistently behaves as if the request sent by the form is not a POST request. Consequently, it executes the statements within the else block, indicating that it wasn't a POST request. Here's the code snippet: @csrf_exempt def verify_otp_view(request, app_user_id): app_user = AppUser.objects.get(id=app_user_id) last_web_otp = app_user.password if request.method == "POST": form = OTPForm(request.POST) if form.is_valid(): entered_otp = form.cleaned_data['otp'] if entered_otp == last_web_otp: # Success, the OTP is correct login(request,app_user.user) return HttpResponseRedirect(reverse('web_app')) else: # Failure, the OTP is incorrect # messages.error(request, 'Incorrect OTP. Please try again.') context = {'form': form, 'app_user_id': app_user_id} return render(request, "verify_otp.html", context) else: form = OTPForm() context = { 'form': form, 'app_user_id':app_user_id } return render(request, "verify_otp.html", context) # Add the following line to ensure a response is returned for all cases context = { 'form': form, 'app_user_id':app_user_id } return render(request, "verify_otp.html", context) <div class="container" style="text-align: center;margin: auto;"> <!-- Add form with OTP input field here --> <form method="POST" action="{% url 'verify_otp' app_user_id %}"> {% csrf_token %} <div class="form-group"> <label for="id_otp">OTP:</label> <input type="text" name="otp" class="form-control" id="id_otp"> </div> <input type="submit" value="Submit" class="btn btn-primary"> <a href="{% url 'login_view' %}" class="btn btn-secondary">Back</a> </form> .... -
Forbidden (403) CSRF verification failed. Request aborted even though the csrf token is present
I am making a project in Django for an NGO. I keep running in the csrf toke missing error. I have the {% csrf_token %} tag in the form tags. The csrf is working on other forms but isn't working on this form only. here is the html page that is resulting in this error: {% load static %} <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1" /> <title>Assistanza</title> <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-T3c6CoIi6uLrA9TneNEoa7RxnatzjcDSCmG1MXxSR1GAsXEV/Dwwykc2MPK8M2HN" crossorigin="anonymous" /> </head> <body> <!--NavBar --> <nav class="navbar navbar-expand-lg"> <div class="container-fluid"> <a class="navbar-brand" href="#"><img src="{% static 'main/images/navbarlogo.jpg' %}" alt="Logo" width="80" height="40" class="d-inline-block align-text-top" /></a> <div class="container marketing"> <div id=timer></div> </div><br><br><br> <div class="collapse navbar-collapse" id="navbarSupportedContent"> <ul class="navbar-nav me-auto mb-2 mb-lg-0"> </ul> </div> </div> </nav> <div><br><br></div> <script> var timeLimit = {{ time_limit }}; var timer = setInterval(function () { var minutes = Math.floor(timeLimit / 60); var seconds = timeLimit % 60; // Display time in minutes and seconds document.getElementById('timer').innerHTML = 'Time Left: ' + minutes + 'm ' + seconds + 's'; // Check if time is up if (timeLimit <= 0) { clearInterval(timer); // Redirect to the completion page window.location.replace("{% url 'test_complete' %}"); } timeLimit--; }, 1000); // Update every 1 second </script> <div … -
Keep track of no of records created for django model daily without realtime db query except for the first time of application startup
I have the following django model class Token(models.Model): material_to_load = models.ForeignKey(Material,on_delete = models.CASCADE) vehicle_no = models.CharField(max_length=20) driver_name = models.CharField( "Driver Full Name", max_length=20, validators=validations.valid_full_name, help_text='Name as on driving license' ) valid_from = models.DateField("Entry Date") valid_until = models.DateField("Valid Till",null=True,blank=True) created_dt = models.DateTimeField(auto_now_add=True) modified_dt = models.DateTimeField(auto_now=True) entry_timestamp = models.DateTimeField(blank=True,null=True) exit_timestamp = models.DateTimeField(blank=True,null=True) I need to implement a daily counter for the above model to keep track of daily record creation under various filters for example count of tokens created for each material (only 4 materials are there),and for each material I need to generated a priority number (number in series start from 1 reset at midnight) at the time of updation of the entry_timestamp. How to do the above thing without having everytime db query. is there any solution for that... something like django signals or singleton object with incremental method . -
Providing end users with data integration capabilities on front end
I am doing research as part of new product development and unable to find the right answer. Would like to provide end users with data integration and load to back end capabilities. They will connect to different sources (excel, dbs, other applications) of financial data, select tables and features needed to be loaded to back end. Instead of building from scratch, any tech out there that we could integrate direct to provide these features to end users. Backend is Django and front end is react for current stack with Postgres as db. Tried to search in Django and react documentation as well as google -
How to overcome Django error - [ERROR] Runtime.ImportModuleError: Unable to import module 'core.wsgi': No module named 'django'
I am having issues setting up my Django app onto AWS using Lambda and API gateway. Here is my application configuration: The Django app I have created is a simple automation dashboard with the project being core and an app called data The data app has a few charts and the information for the charts flow from the SQLite db. The website gets loaded successfully when I run python manage.py runserver. I am able to access the site locally from http://127.0.0.1:8000/admin/ Most of the components were built based on the setup explained here. The app is configured with a virtual env as mentioned in the above link except my python version is 3.11.4. The mod_wsgi version is 5.0.0. I have setup the lambda and API gateway onto an AWS account using SAM. Here is the template.yaml file: AWSTemplateFormatVersion: '2010-09-09' Transform: AWS::Serverless-2016-10-31 Description: Automation Backlog dashboard django app on AWS Lambda Resources: automationbacklogdashboard: Type: AWS::Serverless::Function Properties: Handler: core.wsgi.application Runtime: python3.11 CodeUri: /Users/arjunvijayakumar/Desktop/workspaces/automation-backlog-dashboard MemorySize: 256 Timeout: 30 Events: QAAutomationBacklogDashboard: Type: Api Properties: Path: / Method: ANY Problem: When I run sam local start-api, the application starts successfully. When I access the URL provided http://127.0.0.1:3000/ I get the following error: (env) arjunvijayakumar@V536M7J663 automation-backlog-dashboard … -
I'm getting an error with the event.preventDefault(); That it not a function
I'm made a dajngo website where if the product have a field with is_active = False, it gonna remove it from the basket in the shop. So wrote this script in html file: {% if table.is_active %} <div data-index="{{ table.id }}" class="table table-item"> <a href="{% url 'table_details' table.id %}" class="table-link"> <img class="table-img ib" src="{{ table.image.url }}" alt=""> <p class="title ib">{{ table.name }}</p> </a> </div> {% else %} <div data-index="{{ table.id }}" class="table table-item"></div> <script> console.log("hello world 1") $(document).ready(function (event) { console.log("hello world 2") event.preventDefault(); var tablid = $(this).data('index'); console.log(tablid) $.ajax({ type: 'POST', url: '{% url "basket:basket_delete" %}', data: { tableid: $(this).data('index'), csrfmiddlewaretoken: "{{csrf_token}}", action: 'post' }, success: function (json) { $('.table-item[data-index="' + tablid + '"]').remove(); document.getElementById("subtotal").innerHTML = json.subtotal; document.getElementById("basket-qty").innerHTML = json.qty }, error: function (xhr, errmsg, err) {} }); }) </script> {% endif %} and in the console.log it gives me a warning and error with the same text, # Uncaught TypeError: event.preventDefault is not a function # at HTMLDocument.<anonymous> (basket/:116:27) # at e (jquery-3.5.1.min.js:2:30005) # at t (jquery-3.5.1.min.js:2:30307) So what I did I tried to remove the line with event.preventDefault(), but then the data-index of the div stoped being used in the tablid varibale, and when I coneole.log(tablid), it … -
How to get the profile picture of a user who is not logged in?
I made this user info page which is supposed to show the profile of the user you click on it is supposed to work even when the user is not logged in but I cannot get the username or profile picture of the user I chose I could only display the profile of the currently logged in user there what should I do?? if I need to post another page please let me know \ Thanks in advance prof.html {% extends "base.html" %} {% load static %} {% block content %} <div class="frame"> <div class="center"> <div class="profile"> <div class="image"> <div class="circle-1"></div> <div class="circle-2"></div> <div style="margin-left: -20px"> <img src="{{ user.profile.image.url }}" width="110" height="110"> </div> </div> <div style="margin-top: 30px"></div> <div class="name"> {{ user.username }} </div> <div class="job">Visual Artist</div> <div class="actions"> <button class="btn">Follow</button> <button class="btn">Message</button> </div> <div class="sociic"> <a href="{% url 'home' %}"><i class="fa fa-telegram"></i></a> <a href="#"><i class="fa fa-envelope-o"></i></a> <a href="{% url 'home' %}"><i class="fa fa-linkedin-square"></i></a> <a href="#"><i class="fa fa-github"></i></a> </div> </div> <div class="stats"> <div class="box"> <span class="value">523</span> <span class="parameter">Stories <i class="fa fa-pencil"></i></span> </div> <div class="box"> <span class="value">1387</span> <span class="parameter">Likes <i class="fa fa-heart-o"></i></span> </div> <div class="box"> <span class="value">146</span> <span class="parameter">Follower <i class="fa fa-thumbs-o-up"></i></span> </div> </div> </div> </div> <style> @import url(https://fonts.googleapis.com/css?family=Open+Sans:600,300); .frame { filter: …