Django community: RSS
This page, updated regularly, aggregates Django Q&A from the Django community.
-
name 'get_total_discount_item_price' is not defined
I'm trying to get the total price of all the items. But this error pops out whenever I try to do it. What can that due to? It says that the name is not defined even though I've written it and it should perform the task correctly. This is the HTML code: {% for object in orders %} <div class="row justify-content-start"> <div class="col col-lg-5 col-md-6 mt-5 cart-wrap ftco-animate"> <div class="cart-total mb-3"> <h3>Cart Totals</h3> <p class="d-flex"> <span>Subtotal</span> {% if object.get_total %} <span> ${{ object.get_total }}</span> </p> {% endif %} <p class="d-flex"> <span>Delivery</span> <span>$0.00</span> </p> <p class="d-flex"> <span>Discount</span> <span>$3.00</span> </p> <hr> <p class="d-flex total-price"> <span>Total</span> <span>$17.60</span> </p> </div> <p class="text-center"><a href="{% url 'core:checkout' %}" class="btn btn-primary py-3 px-4">Proceed to Checkout</a></p> </div> </div> {% endfor %} this is the models.py: class OrderItem(models.Model): user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE) item = models.ForeignKey(Item, on_delete=models.CASCADE) ordered = models.BooleanField(default=False) quantity = models.IntegerField(default=1) def __str__(self): return f"{self.quantity} of {self.item.title}" def get_total_item_price(self): return self.quantity * self.item.price def get_total_discount_item_price(self): return self.quantity * self.item.discount_price def get_final_price(self): if self.item.discount_price: return get_total_discount_item_price() return self.get_total_item_price() class Order(models.Model): user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE) items = models.ManyToManyField(OrderItem) start_date = models.DateTimeField(auto_now_add=True) ordered_date = models.DateTimeField() ordered = models.BooleanField(default=False) def __str__(self): return self.user.username def get_total(self): total = 0 for order_item in self.items.all(): … -
Heroku Account Dashboard Issue
Hi all i am getting this error when i log into my Heroku account. Item could not be modified: Unable to fetch account It was working fine for the better part o the day any idea what would be the cause? -
How to change url in Django
I am new to Django and maybe formulation of the question is not the best, so sorry for that. I am trying to implement a search functionality and it seems to work fine, except it is not matching the path. I want it to look like this after I click submit button: 'search/query=value', but I get this instead: '/ru/”/ru/search/”?csrfmiddlewaretoken=SSoBp5K7E0EgRFQNyIvECSXFohG5ACp9IKNGKXMOYNmdc8BqqHeKLR8vawHuVxwf&”txtSearch”=1'. I am using i18n to prefix paths with language. Here is code that relevant to the problem: urls.py urlpatterns = [ path('', HomeView.as_view(), name='home'), path('search/', search, name='search'), ] home.html <form id=”search” method=”GET” action=”{% url 'search' %}”> <input type=”text” id=”txtSearch” name=”txtSearch”> <button type=”submit”>Submit</button> </form> views.py def search(request): if request.method == 'GET': query = str(request.GET['”txtSearch”']) print(query) queryset = [] queries = query.split(' ') for q in queries: print(q, 'is q') articles = Article.objects.filter( Q(name__icontains=q) | Q(body__icontains=q) ).distinct() for article in articles: queryset.append(article) return render(request, 'search.html', {'articles': list(set(queryset))}) Thank you! -
Django Rest Framework + psycopg2 : InterfaceError: cursor already closed
I have a problem with psycopg2. It fails to perform some queries. I have traced exceptions and it says: django.db.utils.InterfaceError: cursor already closed I have already seen some similar cases on the Internet, tried all the recommendations, but no luck. I use Django Rest Framework, and while requesting some endpoints it causes error, just in some requests. I monitored error.log file and I see 15-20 requests failed with HTTP 500 error. Is there any solutions for this problem? Software Versions: djangorestframework == 3.12.1 django == 3.0.5 Python 3.8 This is uswgi.ini file which I run on the server. Socket is used by NGINX. [uwsgi] project = DjangoProject base = /opt/django-project chdir = %(base) module = %(project).wsgi:application home = %(base)/venv gid = www-data uid = www-data master = true processes = 5 socket = /tmp/%(project).sock chmod-socket = 664 vacuum = true harakiri = 60 max-requests = 10000 I tried to solve problem by increasing connections to Postgresql. But no change, the error still remains. Snippet from postgresql.conf file: max_connections = 2000 shared_buffers = 800MB Complete stack trace: Internal Server Error: /api/users/ Traceback (most recent call last): File "/opt/django-project/venv/lib/python3.8/site-packages/django/db/utils.py", line 97, in inner return func(*args, **kwargs) psycopg2.InterfaceError: cursor already closed The above … -
Adding custom usercreationform attributes to admin panel
I have extended the default user creation form and added some custom attributes but they are not showing up in the admin site, can someone let me know how to register them in the admin panel. from django.contrib.auth.forms import UserCreationForm from django.contrib.auth.models import User from django import forms class UserCreate(UserCreationForm): full_name = forms.CharField(max_length=200) channel_name = forms.CharField(max_length=200) email = forms.EmailField() class Meta: model = User fields = ["username", "email", "password1", "password2", "full_name", "channel_name"] def save(self, commit=True): user = super(UserCreate, self).save(commit=False) user.full_name = self.cleaned_data["full_name"] user.channel_name = self.cleaned_data["channel_name"] user.email = self.cleaned_data["email"] if commit: user.save() return user -
How to configure crontab to run Django command?
I run a Debian 10 system have the following shell file named "update.sh": #!/bin/bash cd home/user/djangoprojet source /env/bin/activate python manage.py update I run a root user and set "chmod +x update.sh". When I run "home/user/djangoprojet/update.sh", executing the script works perfectly. I now used "crontab -e" to run the script every minute: * * * * * home/user/djangoprojet/update.sh > testcron.log However, the script is not executed. When I run "grep CRON /var/log/syslog", I get the following result, which indicates that crontab runs: Jan 30 15:08:01 vServer CRON[22036]: (root) CMD > (home/user/djangoprojet/update.sh > testcron.log) Jan 30 15:08:01 vServer CRON[22035]: (CRON) info (No MTA installed, discarding output) The "testcron.log" file, located in the root directory, is empty - although the script would generate an output, if it ran. Somewhere on StackExchange I also found to execute this command /bin/sh -c "(export PATH=/usr/bin:/bin; home/user/djangoprojet/update.sh </dev/null)" which works perfectly. How can I configure crontab correctly such that my script runs? Thanks! -
Show private content to specific users in Django
I'm building a very simple website where a user authenticates and accesses a personal page from where they can download their paychecks. I've already implemented the login view, that redirects the user to the profile page. Now in the profile page, I need to add a list of paychecks to download. In order to do that, I need to take them from a static sub-directory with the same name as the user: static/paychecks/username I've been reading about serving static files, but I can't figure out how to do this specifically. Any help will be much appreciated. -
How to pass field from submitted form into url in Django?
I am trying to submit a form, save to database and then show the cleaned_data on a new url. In the form I have a field called job_number. I would like to send the cleaned_data over to 127.0.0.1:8000/quotes/job_number quote/views.py: @login_required def quote_view(request): data_form = QuoteInformationForm() if request.method == "POST": data_form = QuoteInformationForm(request.POST) if data_form.is_valid(): data_form.save(commit=True) return redirect('quote') else: print('Error') return render(request, "index.html", {'data_form': data_form}) @login_required def submitted_quote(request): return render(request, "quote.html") urls.py: urlpatterns = [ path('home/', quote_view, name='home'), path('quote/', submitted_quote, name='quote'), Currently all this does is open the form at http://127.0.0.1:8000/home/ using index.html. When I submit it will send the info to the database and redirect me to http://127.0.0.1:8000/quotes. This is fine. Now I just need to show the cleaned data on this url and change the url to include the job_number at the end. How can I do this? -
Django model serialization returns only primary key for foreign key
i am building blog site with Django. After serialization, the Post model which has a foreign key field of Django built-in User model, Post models are returned with the integer foreign key reference to the User model while i am expecting the whole User object data rather only getting the integer number. the Post models.py: from django.db import models from django.contrib.auth.models import User class Post(models.Model): author = models.ForeignKey(User,on_delete=models.CASCADE) body = models.TextField() created_at = models.DateTimeField(auto_now_add=True) updated_at = models.DateTimeField(auto_now=True) the serializers.py: from rest_framework import serializers from .models import Post class PostSerializer(serializers.ModelSerializer): class Meta: fields = ('id', 'author','body','created_at') model = Post the views.py: from django.shortcuts import render from rest_framework import generics from .models import Post from .serializers import PostSerializer from .permissions import IsAuthorOrReadOnly class PostList(generics.ListCreateAPIView): serializer_class = PostSerializer queryset = Post.objects.all().order_by('-created_at')#sorted by created_at descending class PostDetail(generics.RetrieveUpdateDestroyAPIView): permission_classes = (IsAuthorOrReadOnly,) serializer_class = PostSerializer queryset = Post.objects.all() i want { "id": 15, "author": {"fisrt_name":"firstname","last_name":"namelast","username":"username1","email":"example@gamil.com"}, "body": "hello world2", "created_at": "2020-12-23T13:53:17.741635Z" } instead of { "id": 15, "author": 21, "body": "hello world2", "created_at": "2020-12-23T13:53:17.741635Z" } -
Hello, I have a problem with submiting a form in django
I have tried to create a simple form of registration with 'POST' method, and then at 'views.py' I tried this: from django.shortcuts import render,redirect from django.contrib.auth.models import User,auth # Create your views here. def register(request): if request.POST: first_name = request.POST["first_name"] last_name = request.POST["last_name"] username = request.POST["username"] email = request.POST["email"] password = request.POST["password1"] password2 = request.POST["password2"] user = User.objects.create_user( username=username, password=password, email=email, first_name=first_name, last_name=last_name ) user.save() return redirect("/") else: return render(request, "register.html") to prevent the page from going to the same url again like '..../register/register' since i have been using the same file 'register.html' for submiting data and fetching the page : <form action="register" method="post"> {%csrf_token%} <br> First_Name : <br> <input type="text" maxlength="30" placeholder="First Name" name="first_name" required> <br> Last_Name : <br> <input type="text" maxlength="30" placeholder="Last Name" name="last_name" required> <br> User_Name : <br> <input type="text" maxlength="30" placeholder="User Name" name="username" required> <br> Email : <br> <input type="email" placeholder="Email" name="email" required> <br> Password :<br> <input type="password" maxlength="30" placeholder="Password" name="password1" required> Confirm_Password :<br> <input type="password" maxlength="30" placeholder="Confirm Password" name="password2" required> <hr> <input type="submit"> </form> this is my project file urls : from django.contrib import admin from django.urls import path,include from django.conf import settings from django.conf.urls.static import static urlpatterns = [ path('', include('website.urls')), path('accounts/', include('accounts.urls')), path('admin/', … -
A QuerySet from a recursive Many-to-many model
Explanation There is a Tag model. Tags are used in relation to other tags. For example, "New Year Gift", "Birthday Gift" are marked with the "Gift" tag: Lvl1: Gifts / \ Lvl2: New Year Gifts Birthday Gifts / \ Lvl3: Card Toys Model Looks something like this: class Tag(models.Model): slug = models.SlugField(max_length=64) tag = models.ForeignKey('self', on_delete=models.SET_NULL, blank=True, null=True, related_name='tags') Problem Now all tags in the system are organised in 3 levels: Top level Sub-level Sub-sub-level E.g.: Gifts > Birthday Gift > Toy Goal The goal is to construct a QuerySet which will return 3-level list, so it is passed into context and the template simply iterates over it and builds a 3-level DOM structure. The ultimate goal is to solve this in the most efficient way (in terms of DB/CPU load). I would think this could be done using annotating and some extra joins and values list. Any clues? -
How to pass value by request?
I have a middleware that maps websites for companies. I want to know which company the site belongs to and go through the request to be accessed in a view. The following example shows what I am wanting to do. #middleware.py virtual_hosts = { "www.example-1.com": "company1", "www.example-2.com": "company2", "www.example-3.com": "company3", } class HostMiddleware: def __init__(self, get_response): self.get_response = get_response def __call__(self, request): host = request.get_host() #How can I pass the value? request.atribute = virtual_hosts.get(host) response = self.get_response(request) return response How can I pass an attribute through the request? -
Sending multiple images from Django to React
I am working on project in which I am using Django as backend and React as frontend . I am using rest framework to feed the front end . I want to show multiple image on client side . One way is to the convert image into Base64 and send it using rest framework . But it is quite inefficient for multiple images (first converting those images and sending it ). Another way is I can pass my Django media url in response .The issue with this approach is that my images are private . This exposes my media url and maybe someone other can access those images. I would be grateful if someone can point me in right direction . -
Add clickable link to admin page List_view
I want to add a clickable link to admin list_view for a specific app that will redirect me to a html file i created, I have created a view.py like this from django.shortcuts import render from . models import * from django.contrib.auth.decorators import login_required @login_required def transaction_print(request, transaction_id): transaction = Transaction.objects.get(id=transaction_id) return render(request, 'report.html', {'transaction': transaction}) and my urls.py from django.urls import path from . import views urlpatterns = [ # path('', views.transaction_print, name='transaction_print'), path('transaction/<int:transaction_id>/', views.transaction_print, name='transaction_print'), ] I created the report.html at (root_dir/calculator/templates/report.html) Now im not sure how to make a method at models.py to return maybe my views as a link to be add to list_view, or what is the best approach to achieving that. Thanks! -
Heroku Environment Variables for S3 Bucket Not Being Read in Container Instance of Django App
I am pushing my Django app to Heroku as a container instance, but I am getting problems where it doesn't appear to be reading the environment variables. They are set using "heroku config:set AWS_STORAGE_BUCKET_NAME='my_bucket'" and so on. My python code working in development and uses the bucket storage successfully, but when pushing to Heroku I get the error shown which implies it is not passing the value for the bucket name. remote: if not VALID_BUCKET.search(bucket) and not VALID_S3_ARN.search(bucket): remote: TypeError: expected string or bytes-like object My settings file looks like this: AWS_STORAGE_BUCKET_NAME = os.environ.get('AWS_STORAGE_BUCKET_NAME') AWS_S3_REGION_NAME = os.environ.get('AWS_S3_REGION_NAME') AWS_ACCESS_KEY_ID = os.environ.get('AWS_ACCESS_KEY_ID') AWS_SECRET_ACCESS_KEY = os.environ.get('AWS_SECRET_ACCESS_KEY') AWS_S3_CUSTOM_DOMAIN = '{}.s3.amazonaws.com'.format(AWS_STORAGE_BUCKET_NAME) STATICFILES_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage' STATICFILES_LOCATION = 'static' STATICFILES_STORAGE = 'custom_storages.StaticStorage' MEDIAFILES_LOCATION = 'media' DEFAULT_FILE_STORAGE = 'custom_storages.MediaStorage' I have a .yml file and I am thinking that I might need some configuration in there, but can someone help advise what that should be? It looks as below and I have tried adding environment variables under the config section to see if it makes a difference, but it didn't. setup: addons: - plan: 'heroku-postgresql:hobby-dev' as: DATABASE config: BUILD_WITH_GEO_LIBRARIES: '1' DISABLE_COLLECTSTATIC: '1' build: packages: - gdal-bin languages: - python run: web: gunicorn booksapp.wsgi --log-file - -
Django + plotly-dash: cannot render graphs side to side
I have followed this Subplot ( Side to side ) in python Dash and How to add multiple graphs to Dash app on a single browser page?, to find a way to get graphs rendering side to side in my template. I cannot get it to work, the size of the graphs are adjusting well, but they keep rendering one below the other. I am confused about what is going wrong, and as I am just picking up dash, I am struggling to identify the root cause of the issue. Here is my python file: import dash_core_components as dcc import dash_html_components as html from dash.dependencies import Input, Output import plotly.graph_objs as go from django_plotly_dash import DjangoDash import pandas as pd import dash import dash_core_components as dcc import dash_html_components as html import plotly.express as px from django_plotly_dash import DjangoDash external_stylesheets = ['https://codepen.io/chriddyp/pen/bWLwgP.css'] #external_stylesheets = app = DjangoDash('tryout', external_stylesheets=external_stylesheets) df_bar = pd.DataFrame({ "Fruit": ["Apples", "Oranges", "Bananas", "Apples", "Oranges", "Bananas"], "Amount": [4, 1, 2, 2, 4, 5], "City": ["SF", "SF", "SF", "Montreal", "Montreal", "Montreal"] }) fig = px.bar(df_bar, x="Fruit", y="Amount", color="City", barmode="group") app.layout = html.Div(children=[ # All elements from the top of the page html.Div([ html.Div([ html.H1(children='Hello Dash'), html.Div(children=''' Dash: A web application … -
Error with Django application deployment on Heroku
Please, help me fix this issue with Heroku. I wanted to host my Django & python application on Heroku but having this error coming up. This is the error getting from my browser: this is the error getting in my prompt after doing heroku logs --tail: 2021-01-29T19:05:21.512000+00:00 heroku[run.6267]: Starting process with command `python manage.py migrate` 2021-01-29T19:05:29.245349+00:00 heroku[run.6267]: Process exited with status 0 2021-01-29T19:05:29.281276+00:00 heroku[run.6267]: State changed from up to complete 2021-01-29T19:12:55.201869+00:00 heroku[router]: at=error code=H14 desc="No web processes running" method=GET path="/" host=grouppublishingindia.herokuapp.com request_id=1cd6be75-9711-4890-ac37-542c02731f37 fwd="103.252.25.76" dyno= connect= service= status=503 bytes= protocol=https 2021-01-29T19:13:01.315149+00:00 heroku[router]: at=error code=H14 desc="No web processes running" method=GET path="/favicon.ico" host=grouppublishingindia.herokuapp.com request_id=9cb635ac-f755-437c-9706-b956967f9f32 fwd="103.252.25.76" dyno= connect= service= status=503 bytes= protocol=https 2021-01-29T19:14:17.641461+00:00 heroku[router]: at=error code=H14 desc="No web processes running" method=GET path="/" host=grouppublishingindia.herokuapp.com request_id=d8ed6b4d-3fe4-4c3a-95d7-fc1a4bc7cd52 fwd="103.252.25.76" dyno= connect= service= status=503 bytes= protocol=https 2021-01-29T19:14:20.774568+00:00 heroku[router]: at=error code=H14 desc="No web processes running" method=GET path="/favicon.ico" host=grouppublishingindia.herokuapp.com request_id=61570fe1-d1d3-41d0-846d-8f482e9f8bfe fwd="103.252.25.76" dyno= connect= service= status=503 bytes= protocol=https 2021-01-29T19:16:09.470063+00:00 heroku[router]: at=error code=H14 desc="No web processes running" method=GET path="/" host=grouppublishingindia.herokuapp.com request_id=19bd2fb7-9739-4a80-b881-759f36c0e5b6 fwd="103.252.25.76" dyno= connect= service= status=503 bytes= protocol=https 2021-01-29T19:16:13.909655+00:00 heroku[router]: at=error code=H14 desc="No web processes running" method=GET path="/favicon.ico" host=grouppublishingindia.herokuapp.com request_id=321e5a3a-798a-42ce-a9ab-39786097717f fwd="103.252.25.76" dyno= connect= service= status=503 bytes= protocol=https 2021-01-29T19:25:36.896690+00:00 heroku[router]: at=error code=H14 desc="No web processes running" method=GET path="/" host=grouppublishingindia.herokuapp.com request_id=13206d28-14c4-4fc1-b57a-2d6b82ab05c9 fwd="103.252.25.76" dyno= connect= service= … -
How do I rank blog posts by sentiment in their comments in django?
I'm using TextBlob and I'm trying to add the polarity part of the result into the Comment model and then adding the average of the comments' polarities into the Post model so it can be sorted. I'm new to this stuff, that is why I'm stuck. Help will be appreciated. -
Django app on Windows Server 2012 - HTTP Error 500.0 - The FastCGI process exited unexpectedly
I setup a django "hello world" app IIS (Windows Server 2012). The application is run successfully using the Django web server. However, when I tried to install in on IIS (following the instructions provided here) I get an HTTP 500 error with the message "python.exe - The FastCGI process exited unexpectedly". I have seen numerous related posts on stackoverflow, but nothing seems to work for me. Based on the guidance I have checked file permissions on both the app and virtual environment folder but they in my opinion this should not be the issue as the users IUSR and IIS_IUSRS can Read & execute, Read and List folder contents. I have tried also to run wfastcgi-enable based on the instructions provided by this post but I get the error "ensure your user has sufficient privileges and try again". Please note that I tried running it both from an "elevated" command line and also power shell with no results. I have reinstalled python to make sure it is installed for "all users" (as suggested by this post) but I get an error "0x80070659 - This installation is forbidden by system policy". I looked in the Event viewer but I could not … -
Django urls.py + React router
I built a Django API and a react frontend to consume the API. I'm using react-router and can navigate just fine until I refresh the page. I then get a Not Found error form Django. I'm not sure how to set up these paths with Django so it knows what to serve. api/urls.py urlpatterns = [ path('', views.apiOverview, name='api-overview'), path('product-list', views.product_list, name='product-list'), path('product/<str:slug>', views.product_detail, name='product-detail'), path('images/<str:fk>', views.product_images, name='product_images'), ] urls.py urlpatterns = [ path('', TemplateView.as_view(template_name="index.html"), name='app'), path('admin/', admin.site.urls), path('api/', include('api.urls')), ] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) app.js function App() { return ( <Router> <Nav /> <div className="App"> <Switch> <Route path="/products/:slug" exact component={ ProductDetail } /> <Route path="/products"> <Projects /> </Route> <Route path="/"> <div className='container'> <Header /> <hr /> <h2 className="section-title">Featured Products</h2> <ProductsListHome /> </div> </Route> </Switch> </div> <Footer /> </Router> ); } -
Is there a package in Atom IDE to help development/debugging Django projects as it is possible in VSCode/PyCharm?
Is there a package in Atom to help development/debugging Django projects as it is possible in VSCode/PyCharm? I went through many packages docs but I could not find any setting the packages autoimport and proper debugging tools (breakpoint, vars inspection, etc). Any suggestion? -
create_user() takes from 2 to 4 positional arguments but 5 were given django
I try to create user use User.objects.create_user. But it show error. create_user() takes from 2 to 4 positional arguments but 5 were given myuser = User.objects.create_user(username , email, password, friendid) -
Django Views redirect('homepage')
I'm stuck and don't understand why here my problem: I would like to return context if objects exists else redirect to homepage and raise error Objects.DoesNotExist. Here My Code : Views class PageDetail(TemplateView): """ Page View """ template_name = 'page_detail.html' def get_context_data(self, **kwargs): context = super(PageDetail, self).get_context_data(**kwargs) try: context['news'] = News.objects.filter(is_active=True).order_by('-date_created')[:4] except: pass try: context['page'] = Pages.objects.get(slug=kwargs.get('slug'), is_active=True) except Pages.DoesNotExist: return redirect('homepage') return context But I got this error : raise TypeError('context must be a dict rather than %s.' % context.__class__.__name__) TypeError: context must be a dict rather than HttpResponseRedirect. Tell me if you need more infos Thanks -
Get http://localhost:8000/Stack/script.js net:: Err_Aborted 404 / Django project
So I am attempting to build a simple to-do app, but when trying to work with some javascript to make the home page, I get the error detailed above (Get http://localhost:8000/Stack/script.js net:: Err_Aborted 404 ). I don't understand what I am doing wrong because this is my first time trying to work with javascript in my Django projects. Below is my code settings.py INSTALLED_APPS = [ "django.contrib.admin", "django.contrib.auth", "django.contrib.contenttypes", "django.contrib.sessions", "django.contrib.messages", "django.contrib.staticfiles", "Stack.apps.StackConfig", "crispy_forms", ] STATIC_URL = "/static/" STATICFILES_DIRS = (os.path.join(BASE_DIR, "static"),) STATIC_ROOT = os.path.join(BASE_DIR, "staticfiles") CRISPY_TEMPLATE_PACK = "bootstrap4" base.py <!DOCTYPE html> {% load static %} <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <!-- Bootstrap CSS --> <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-giJF6kkoqNQ00vy+HMDP7azOuL0xtbfIcaT9wjKHr8RbDVddVHyTfAAsrekwKmP1" crossorigin="anonymous"> <link rel="stylesheet" type="text/css" href="{% static 'Stack/styles.css' %}"> <title>Stack | Home </title> </head> <body> {%block content%} {%endblock content%} <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta1/dist/js/bootstrap.bundle.min.js" integrity="sha384-ygbV9kiqUc6oa4msXn9868pTtWMgiQaeYH7/t7LECLbyPA2x65Kgf80OJFdroafW" crossorigin="anonymous"></script> <script src="Stack/script.js" ></script> If I need to upload any more code to help solve this problem, please let me know. Thank you all. -
django app for loop: views.py or frontend?
I am building a django app which has a list of words. The app now tells the user the first word of the list via a speech function. Then the user can record an audio of a word he sais. This word gets turned into a string in the frontend. Now I want to compare the the word from the user with the first string of a second list that has the same amount of characters as the first list. And this whole process should be repeated with all characters of the first list. Can I do this kind of loop in my views.py or do I have to do it in the frontend?