django-views

Select 3 random items and exclude the one already selected

Select 3 random items and exclude the one already selected Question: I’m trying to display three random drinks in my template, selected from a database of drinks. I currently have the random selection working but also noticed theres a chance of a drink showing up twice. How do I prevent this from happening? Is there …

Total answers: 2

Strange behaviour because of the order of URLs in urls.py django behaviour

Strange behaviour because of the order of URLs in urls.py django behaviour Question: I am doing a mini blog assignment using Django for learning purpose. I noticed a strange behavior in django urls.py when the order of lines is below I am able to make a successful GET call to http://127.0.0.1:8000/blog/blog/create path(‘blog/create’, views.BlogPostCreate.as_view(), name=’blogpost-create’), path(‘blog/<slug:slug>’, …

Total answers: 1

Django cannot add null data from url to database

Django cannot add null data from url to database Question: I create model like this which it should recieve null value without error class ReceiveData(models.Model): api_key=models.ForeignKey(DeviceKey,on_delete=models.CASCADE) field1= models.FloatField(null=True) field2= models.FloatField(null=True) field3= models.FloatField(null=True) I use is_float to check type of data before add to database. def is_float(element: any) -> bool: #If you expect None to be …

Total answers: 1

Better alternative for passing complex object from template to views.py on POST call

Better alternative for passing complex object from template to views.py on POST call Question: In views.py on GET call, I create a random list of questions (its a complex object, list of dictionaries) and I send that list to the template (HTML) file using return render(request, ‘some_page.html’, args). I show one question at a time …

Total answers: 1

Django Not Found: /media/ , GET /media/ HTTP/1.1" 404 2679

Django Not Found: /media/ , GET /media/ HTTP/1.1" 404 2679 Question: I am currently building a project which i have to use media. Since i have used media before i copy pasted everyting from my other project and altough the original is working my current project is not. I can upload and select fotos thru …

Total answers: 2

ColumnFormFormSet objects has no attribute ‘save’

ColumnFormFormSet objects has no attribute ‘save’ Question: I want to create 30 fields in the design.html, after I successfully added that using django formset When I try to submit the form instead of saving the field to the database, it throws me an error saying ‘ColumnFormFormSet’ object has no attribute ‘save’ how can I solve …

Total answers: 1

How to hash stored passwords in mysql using pbkdf2_sha256 using Django

How to hash stored passwords in mysql using pbkdf2_sha256 using Django Question: I have list of user passwords stored as plain text. I think I need a script to run over the stored passwords and hash them. I’m new to Django and not sure where to start or how. I created login and creating accounts …

Total answers: 1

rtsp stream with django

rtsp stream with django Question: I’m trying to put a url based on my views.py but it returns the error: Reverse for ‘transmition’ not found. ‘transmition’ is not a valid view function or pattern name. project urls.py: from django.contrib import admin from django.urls import path, include from django.conf.urls.static import static from django.conf import settings from …

Total answers: 1