Questions tagged [django]

Django, a Python-based framework, stands out as an open-source solution for server-side web application development. Its purpose lies in simplifying the creation of intricate data-driven websites and applications, prioritizing concise code, eliminating redundancy, and emphasizing explicitness over implicitness.

Step-by-step guide: Deploying your Django application on Google App Engine

As I attempt to launch a Django application on Google App Engine, I am faced with numerous errors along the way. I first tested out this example: https://github.com/GoogleCloudPlatform/appengine-django-skeleton, only to encounter the error: ImportError: ...

NumericError on /post_create/ unrecognizable numeric value: 'manish'

I have a unique vision: I want to create posts with different authors in separate models def post_creation(request): author, initiated = Author.objects.get_or_create(name=request.user.username) form = CreationForm(request.POST or None , request.FILES or ...

What are the solutions for fixing a JSONdecode issue in Django when using AJAX?

I am encountering a JSONDecodeError when attempting to send a POST request from AJAX to Django's views.py. The POST request sends an array of JSON data which will be used to create a model. I would greatly appreciate any helpful hints. Error: Exception T ...

What is causing the issue with this API request's functionality?

I have set up an API using Django-REST Framework and am currently working on connecting it to my frontend. One of the endpoints I created retrieves the last four winners, and when I test it, everything seems to be functioning properly. async function getL ...

What is the best way to refresh a page during an ajax call while also resetting all form fields?

Each time an ajax request is made, the page should refresh without clearing all form fields upon loading Custom Form <form method='post'> <input type='text' placeholder='product'/> <input type='number' placeholder='cost'/> <input ...

Difficulty in Configuring Form Attributes Using Crispy Forms Manually

I have been working on creating a model form using django-crispy-forms for Django 1.8.4 and django-crispy-forms-1.5.2. I am facing some challenges in modifying the form tag attributes. Even after trying to set self.helper.form_tag = False, the <form> ...

What strategies are most effective for handling secret keys when deploying Django projects using Fabric?

Currently, I am attempting to securely store my SECRET_KEY in an environment variable: # settings/base.py def get_env_variable(var_name): """ Retrieve the environment variable or return an exception """ try: return os.environ[var_name] ...

Unexpected behavior occurs in Django routing with a VueJS single page application when the URL is missing a trailing slash

In my development setup, I am utilizing a Django backend with a VueJS frontend, serving a REST API through Django and using VueJS along with vue-router for the single page application. After reading up on this on Stack Overflow, I found a helpful suggesti ...

implement django self,pk post-save success function

It might seem unconventional, but I'm attempting to utilize a primary key (pk) in a success function to generate a href for loading. The pk will be new and generated by the save() method. What I would like to know is how to send the self.pk pack to the ja ...

Establishing a URL for the Django ImageField model attribute using a custom storage solution designed specifically for Azure Cloud Storage

I am encountering an issue with my Django web application. Users are able to upload images successfully, but for some reason the URLs of these images are not being set properly when stored in Azure Cloud Storage. As a result, when I try to display these im ...

Error encountered in django-cms makemigrations process: Missing module 'packaging' for successful execution

Embarking on my journey with django-cms, I set out to install the CMS following the official documentation. After creating a virtual environment and installing Django and django-cms, I moved on to the next steps which involved using django-admin to create ...

Auto-filling a form with the selected 'id' in Django using JavaScript or AJAX

I am a novice and I want the form to be autofilled when I select a vehicle ID from the template. Here are my models. class Fuel(models.Model): vehicle = models.ForeignKey(Vehicle, on_delete=models.CASCADE) previous_km = models.IntegerField(blank=False, nul ...

Error thrown due to obtaining multiple objects using the `get_or_create` method

Here is a concise snippet of code I have for retrieving or creating a conversation for the current user: c, created = Conversation.objects.get_or_create( message__sender=request.user, content_type=get_content_type(request.POST['ct']), ...

A guide on incorporating Django Selenium testing into GitHub Actions

Currently working on a Django project, I have a test case that inherits from django.test.LiveSeverTestCase and utilizes Selenium: from django.test import LiveServerTestCase from selenium.webdriver.chrome.webdriver import WebDriver class FrontEndTestCase(L ...

communicating global variables between Django and JavaScript

I want to make variables from my settings.py accessible in all JavaScript code used throughout my project. What is the best way to accomplish this elegantly? Currently, I am considering two options: Create a context processor and define these globals ...

Using Django's ManyToMany field and displaying it in JSON format

I am attempting to retrieve data in JSON format. I have a ManyToMany field that is only returning the ID, but I also need the contents of it. Below is my models.py: class Pricing(models.Model): name = models.CharField(max_length = 100) price = mod ...

Issue encountered: "Python unable to find module named http_client while attempting to execute Django alongside Django Rest Framework."

My goal is to develop a basic API using the django rest framework. The code in my view looks like this: from django.shortcuts import render from moviestash.models import Movie from moviestash.serializer import MovieSerializer from rest_framework impor ...

Load user information for the current logged in user using Django

Greetings fellow Django beginners! I know this question has been asked before, but I'm having trouble finding a solution that fits my specific situation. Here's the issue: I have a Form with a choice field that gets its options from the databas ...

The Django server fails to display the CSS files upon activation

Despite having all the static files in place, only the plain HTML loads without any styles for some unknown reason. I've attempted using collectstatic and even setting up a new project, but to no avail. STATIC_URL is also properly specified along with ...

Issue with Django-dash memo and news plugin

Recently, I decided to try out a demo of django-dash through this link: https://github.com/barseghyanartur/django-dash. To set up the demo, I had to manually install all the necessary dependencies for django-dash due to some issues with my work computer a ...

I'm currently attempting to upload a file to a Django server utilizing AngularJS 1.6.5. Unfortunately, I'm encountering issues with uploading the file using the $http.patch method

I am currently working on uploading a file from an AngularJS 1.6.5 application to a Django server. However, I am facing some challenges with the 'Content-Type' header that needs to be passed along with the $http.patch method. Here is how my Angular app's c ...

CrispyForms: FormHelper - Easily move the </form> tag to a different location and manage multiple forms from a single model

When utilizing FormHelper and invoking the Form using {% crispy form %}, it generates a Form wrapped within <form> tags. However, my Template is structured into two columns. The first column displays the dynamically generated {% crispy form %}. The ...

Exploring the cleaned_data attribute in a django Form

Recently, I encountered a scenario with my Django form setup that involves using a simple form structure like this: class ContactForm(forms.Form): subject = forms.CharField(max_length=100) message = forms.CharField(widget=forms.Textarea) In my vi ...

The range selector on the x-axis of the Highstock chart is currently showing data only between January 8, 1970, and January 19,

I have a database with data from 1931 to yesterday. I am using Python Django models to retrieve the data and display it using Highstock. The chart only shows data for specific 15 days on the x-axis and the range selector is not functioning properly. Below ...

Adding an image within the body of text in a Django model, where both the text and image coexist

I am currently seeking a method to seamlessly insert an image within the text of my Django-powered blog. My goal is to achieve a layout similar to the one showcased in this example: https://i.stack.imgur.com/cFKgG.png The desired layout consists of two c ...

Enhance the table using Django URL tag along with JQuery

I am currently working on a table that is being populated with user details and I would like to include a Django URL tag within the row, extracting the primary key in the process. Here is an example of what I am trying to achieve: function putTableData(re ...

Real-time Feedback: Providing live updates to users about the current connection status

My task requires pulling data from multiple datasources which can be time-consuming. To enhance user experience, I want to provide real-time information about the progress by displaying messages like "Currently retrieving data from table1" and "Now fetchin ...

Whenever I attempt to log out, the message "Page not found (404)" mysteriously appears

Every time I try to log out, this error message pops up: https://i.stack.imgur.com/whRMU.png This is what my html looks like: https://i.stack.imgur.com/QtUTf.png Here's the code in views.py : https://i.stack.imgur.com/Yscb2.png And here's the code in ...

Having trouble getting the img src to work in Django 2.1 template?

I'm having trouble displaying images in my Django template file. Despite uploading the images to media static files, they do not appear on the template. When I click on the image link in the Django admin page, it shows a "Page not found(404)" error message ...

Using the $ajax method for receiving and handling JSON data

Trying to implement AJAX in my Django app to validate the existence of a username and display an error message if necessary. Below is the code snippet: HTML: <form method="post" id='my_form'> {% csrf_token %} <input id='username' type="t ...

I am having trouble getting Vue.js to function properly within HTML when using Django. Can someone please lend me a

The code run Here is the HTML document: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Register</title> <!--javascript extensions--> <script src='../st ...

Is it possible to accept a file as a form-field input in Django without the need to declare it as a Model?

I recently developed a straightforward API for Tax Analysis by processing a ZIP file received from our supplier using the FastAPI framework. However, due to some technical constraints, I have now decided to migrate my APIs to Django. I have been exploring ...

Access Denied (missing or incorrect CSRF token): /

After encountering an error while trying to copy code from a website in order to create models for a file upload form for mp3 files, I received the following error messages: Forbidden (403) CSRF verification failed. Request aborted. The reason provided fo ...

The Django package does not contain a 'model' attribute. The reference to the 'module' is unresolved

While developing a Realtime chat app with Python, Django, and PyCharm, I encountered an error that says "Unresolved reference 'models'". ...

What is the method for merging multiple Django querysets without combining them?

Having recently started working with the Django framework, I'm facing an interesting challenge that may be of interest to more experienced developers here. Here is the django model in question: STATUS_CHOICES = ( ('CL', 'CLOSED'), ('FR', 'FORWARDE ...

What is the best way to serialize a method within a model?

Is there a way to serialize the get_picture(self) method within this model? I am currently working on a social networking project and I need to serialize this method in order to obtain a JSON URL for the user's profile picture to be utilized in an And ...

Updating the button's appearance after submission using jQuery and Django

I have implemented an ajax "follow" button on my website. Currently, the button's attribute disabled changes to "disabled" after submission. However, I would like to modify the button from "follow" to "unfollow" upon submission, similar to how it works on ...

The callback function for ajax completion fails to execute

My current framework of choice is Django. I find myself faced with the following code snippet: var done_cancel_order = function(res, status) { alert("xpto"); }; var cancel_order = function() { data = {}; var args = { type:"GET", url:"/exch ...

Maximizing the potential of Vue with brunch

I'm having issues while attempting to integrate Vue with Django using brunch. Whenever I try to debug my JavaScript code, I notice that it fails at the following line: import Vue from 'vue/dist/vue.js' The error message displayed is 'Uncaught SyntaxError ...

Form submission not functioning within a bootstrap popover

I'm having trouble saving a URL from an input field (the form is inside a Bootstrap popover) - nothing happens when I click the save button. Below is my HTML code: <div id="popover-content" class="hide"> <form name ="bform" method = "post" actio ...

Encountering difficulties while attempting to decode specific characters from API calls in Django

The response I am receiving from an API contains a character \x96 Upon making the API call, the following error is triggered: 'ascii' codec can't encode character u'\x96' in position 56: ordinal not in range(128) This ...

Error encountered in dynamically generating JSON due to an unterminated string literal

I am attempting to create a JSON variable to pass to a slideshow plugin. Here is the code found within the head section: <script type="text/javascript"> var photos = []; {% for service in company.services.all %} photos.push({ ...

Using Vue to Retrieve Values from a Django Dictionary

When using Vue, the expression {{ game.data }} will return the following data: [ { "game": 1, "turn": 1, "player": 1, "word": "trend", "score": 18 }, { "game": 1, "turn": 2, & ...

showing four forms, unfortunately the last one is malfunctioning

Thank you for taking the time to read this. I've been working on a template that displays 4 forms, each with its own submit button triggering a POST request to the appropriate form. The first 3 forms are functioning correctly, but the last one (Estoq ...

Django view receives all data in QueryDict format when using Angular to send data

As I work with Angular 1.4.4 and Django 1.8, I encountered an issue when posting data from Angular to Django view. The data is received in the form of a whole key in the QueryDict. Upon evaluating request.POST in debug mode, it returns: <QueryDict: {u ...

The Django query for Freelancers using get() resulted in three matches being returned instead of just one

I encountered an issue when trying to assign a freelancer to a specific gig, as the get() method returned more than one Freelancer - in fact, it returned 3! I attempted to retrieve the logged-in freelancer who is creating the gig by using freelancer = get_ ...

What is the most Pythonic way to check if a function has been called with a specific argument in Python?

Looking at my Django codebase, I have an endpoint that performs various tasks. My goal now is to verify if this endpoint is calling the function do_metadata_request with a specific token. Here's the function for reference: def do_metadata_request(url_info, ...

Django seems to strip out the custom html attributes I add to my option tags

I'm facing an issue with adding custom data-* attributes to the option tag within a select element. Despite using a custom template (widget) with Django, it appears that Django is somehow removing my custom attributes in later stages. Here's my custom opt ...

I encountered a PermissionError while trying to log in as an administrator

Just starting out with django and I'm trying to create a superuser. After following all the necessary steps, the terminal confirms that I have successfully created the superuser. However, when I go to the server, I encounter a permission error. I eve ...

Is there a way to send HTML element values to a MySQL Database in Django using Ajax without utilizing a form?

As a Django newcomer, I am currently encountering an issue with posting HTML tag data into the database. I have implemented a "PICK CASE" button that, when clicked, should pass the user_id (hidden in an HTML tag with display:none) and case_id from the tag ...

Developing jpg/png images from .ppt/pptx files with Django

I currently have a PowerPoint file saved on Dropbox at "". My goal is to convert this presentation file into individual slide images (jpg/png..) within my Django template or using a Django def function. Once I have converted the slides, I plan to utilize ...

I'm receiving a 403 Forbidden error while attempting to use @csrf_exempt with an AJAX request. Why is this happening?

I've been attempting to create a simple AJAX request in Django, but I keep encountering the 403 forbidden error in both the Chrome Dev and Django consoles. Despite trying various proposed solutions like @csrf_exempt (to eliminate any potential csrf is ...

Trouble persisting Vue JS form data to Django Rest database

I am currently working on a project involving Django, Django REST, and Vue JS. I have successfully managed to retrieve information from the API to the Vue JS frontend. However, I am facing an issue where data is not being posted to the Django database when ...

The unexpected issue concerning frameworks within PIL

While attempting to install PIL on my Mac OSX, I run sudo python setup.py install and everything seems to be going smoothly until I receive the following output. Has anyone else encountered this issue before? running build_ext --- using frameworks at /S ...

Conceal a specific entry in Django

I have a table displaying records from a model using a for loop. Each row has a button that, when clicked, removes the row. However, upon refreshing the page, the removed rows reappear. I want to prevent this. How can I achieve this? <tabl ...

Conceal form after submission - Django 1.6

I'm currently working on a Django 1.6 project where I have this form: <form action="/proyecto/" method="POST" id="myform"> {% csrf_token %} <table> <span class="Separador_Modulo"></s ...

Facing a Chromedriver malfunction on my Django application hosted on the DigitalOcean App Platform

I am currently working on a web application using Django and the App platform on DigitalOcean. I have integrated Selenium and Chromedriver into my app, and I was able to install Chromedriver using Python libraries such as chromedriver_binary via pip. Howev ...

Sending JSON information from a template to a Django view

In my table, I have an attribute value with a CHAR data type. I am trying to post string data from an HTML template that I obtained from an HTTP GET request using AngularJS. However, when I click the submit button, I receive the following error: `ValueE ...

Tips for selecting the date component in Postgres using Django's ORM

My backend setup is as follows: Postgres 9.5 Python 2.7 Django 1.9 I have a table with a datetime field named createdAt. I want to use Django ORM to select this field with only the date part and group by the createdAt field. For example, the createdA ...

Ways to exchange information (such as temporary paths) among Django test suites

class MyTestCaseA(TestCase): def setUp(self): # Setting up some initial configurations... def test_case(self): # Executing some test scenarios class MyTestCaseB(TestCase): def setUp(self): # Initializing necessary setu ...

Acquire the input value of a form field prior to its submission

In my Django form, I have a field called monitoring_method that is using an autocomplete-light widget. This widget filters the results based on what the user enters in another field called database_type. My question is: Is there any way to access the value ...

Django Dropdown Checkbox

I implemented a form in my Django application that includes a dropdown menu. Models.py class Quiz(models.Model): mtypes = (('A', 'A'), ('B', 'B'), ('C', 'C'), ('D', 'D'), ('E', 'E')) material_type = models.CharField(max_length=255, default=0, ch ...

relocating a feature from within my Django method

Hey, I currently have a function in my view that handles the upload of an image and saves it to a database object. I am looking to refactor this functionality out of my view and either move it to my model or in a separate file. filename_bits = request.FIL ...

Django REST framework error: 'WSGIRequest' does not contain the attribute 'query_params'

Currently, I am in the process of learning about DRF. One thing I attempted was to print out print request.query_params, but unfortunately encountered an error: print request.query_params AttributeError: 'WSGIRequest' object has no attribute 'query_pa ...

Contrasting self.request and request in Django's class-based view

When dealing with class-based views in Django, methods like ListView and DetailView require parameters such as self and request. I recently discovered that within the self there is actually a self.request field. So, what exactly is the distinction between ...

Troubleshooting issue: Django and Javascript - Why is my dependent dropdown feature not

I am new to using a combination of Javascript and Django. Below is the script I have written: <script> $(document).ready(function() { $("#source").change(function() { var el = $(this); var reg = ...

Having trouble importing a Bokeh plot while attempting to integrate it with a Django upload button due to ImportError

I'm having difficulty integrating a Bokeh plot into a Django website that includes an upload button. I started with the example provided here and then followed additional instructions on embedding from here. I have successfully used need-a-minimal-django-f ...

Implementing the integration of Django with Celery, particularly when custom settings need to be seamlessly injected

I'm currently tackling a new project where each developer has their own settings file to work with. When it comes to running Django, I have to execute the following command: python manage.py runserver --settings="databank_web.settings.dqs.dev_houman ...

The process of saving a model in Django

It has come to my attention that there is no assurance that the database will be updated synchronously following a call to save() on a model. To test this, I conducted a simple experiment by sending an ajax call to the method below: def save(request, id) ...

Uploading Files in Django Using Ajax Without a Form

As I explore using Valum's Ajax Upload for file uploads on my Django-based website, I am faced with a challenge. Currently, I am avoiding a traditional form because AU sends the entire upload as POST data in an AJAX request. My current approach involves: ...

What is the best way to prevent Django from caching dynamic templates?

Exploring Django for the first time, I am attempting to show a dynamic server status on my website. It's puzzling why changing the function in my model to return 'cats' doesn't reflect on my browser immediately - there seems to be a delay of about 5 minute ...

Load additional content seamlessly using Ajax in Django without needing to reload the entire navigation bar

I recently started working with Django as I develop my own website. I have created a base.html file which includes the main body, CSS, js, fonts, and navbar that will be present on all pages of my site. The navbar is located in another HTML file called nav ...

A helpful guide on extracting JSON data using AJAX POST method within Django views

I am currently working on parsing JSON data within a Django view, however I have encountered an issue. Below is the code snippet that I am using: $(document).ready(function(){ $("#mySelect").change(function(){ selected = $("#mySelect option:s ...

Enhancing the django admin group with an additional field

I am seeking guidance on how to add a single field to a group of fields within a fieldset in DjangoAdmin. Currently, I have the following setup: class SecretarioAdmin(UserAdmin): model=Secretario def get_fieldsets(self, request, obj=None): ...

Efficiently retrieving Django model relations through JSON

Struggling to properly title this question, but please bear with me as I explain my dilemma. I am in the process of creating an app for my hockey team that involves a django backend and a mobile app using JSON communication (via django-rest-framework). On ...