Django.fun

Questions & Answers about Django, page 2

03.12.2021
1
answers

How to pre format a string to show hyperlink in frontend using django

I have a model in which I accept string data in the char field. this is populated through Django admin field. Models.py class Test(models.Model): overview = models.CharField(max_length=10000, null=True, blank=False) views.py from .models import Test def testView(request): data = Test.objects.all() …

03.12.2021
0
answers

Running javascript code after Django backend Validation

this might be a stupid question but i cant seem to wrap my head around the problem here. I am trying to run a bit of code after a form has been submittet with no errors. The error handling is …

03.12.2021
2
answers

django: bootstrap modal not displaying

To test modal creations in python with django I created a test app named modalTestApp. Then I copied this html that I got off of the bootstrap website and pasted it into the main.html inside the app, …

03.12.2021
2
answers

How do you change the primary key sent to an update view in django?

I want to change the primary key being sent to the update view from the template. Let me explain. Here is my template: <a href="{% url 'new_url' model_instance.pk %}"> {{ model_instance.username }} </a> This model_instance is an instance in …

03.12.2021
1
answers

django test framework token authentication — is there any way to log everyone out?

I understand that token authentication doesnt really have the concept of logging out— that a token merely identifies a user. Is there any way to invalidate all tokens? Maybe via the change of some variable from which all the tokens …

03.12.2021
1
answers

Query one more existing MSSQL DB from Linux

I have deployed django application running on Linux (Ubuntu) in VirtualBox. The settings file database section looks like this. DATABASES = { 'default': { 'ENGINE': 'django.db.backends.sqlite3', 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), } } On the local network there is an MSSQL …

03.12.2021
0
answers

Django Re-Run Migrations on older DB

I've made some changes to my local Django project which has altered my DB structure. I ran my migrations on my local database and everything works fine locally. However my production SQL file does not have these changes made to …

03.12.2021
0
answers

Straight forward modelform doesn't validate on submit of form

I have a fairly simple ModelForm which doesn't validate on submit. Not sure how to debug this. I tried different print statements in my view and everything seems to be proper. This is what I have: # views.py def render_entities(request): …

03.12.2021
0
answers

django make multiple objects for each day with a user imput: start and end date

I'd like to know how i can make multiple object for each day in a Timespan. The users input is a start and end date. My curent moddel looks like this: from datetime import datetime from django.db import models from …

03.12.2021
0
answers

What is the recommended way of naming REST API urls? [closed]

I have a Django REST API. In my app there are users and the users have plans. For plans, I have GET, POST and PUT routes. Every plan has an id and a user_id linking it to a User. Should …

03.12.2021
1
answers

Django_filters apply all chosen filter fields

Hej! :) I want to filter my data before I do some calculations with it with an AND operator. The chosen filter fields should ALL be applied. I added some fields of the mode to the filter function and I …

03.12.2021
2
answers

How to check if some datatype is string or list in python?

I'm trying to add a check here that if the receiver is just a string. then convert that into list else just pass. if type(receiver) == str: receiver=[receiver] error: TypeError: 'str' object is not callable

03.12.2021
0
answers

How to access websocket from another function in another file

I'm trying to make a login page, and I want to access the websocket I've opened up. I'm assuming although I could be wrong, that you only want one websocket open at a time so I'm trying to use the …

03.12.2021
1
answers

when I try to use SyncToAsync() using django and hit 3rd party API endpoint. I get 'SyncToAsync' object has no attribute 'get' error

Iam trying to use async functionality to django views with SyncToAsync(https://docs.djangoproject.com/en/3.2/topics/async/#sync-to-async). I have to hit a 3rd party API using request.get method. But when I hit my endpoint.I get the above error. Any idea how to resolve …

03.12.2021
0
answers

How to create models for friend system in django?

I haven't seen much talks about in the internet . I want to create a friend system for my personal project . I think if i can create it I will have better understanding of ORM which I don't I …

03.12.2021
2
answers

How do I make changes to my Django HTML view file that extends a base template?

I have a Django test project that I am working on, and have been working on it for hours now, and I am stuck. I can't add other html syntax into my html file that extends a base template into …

03.12.2021
0
answers

I'm unable to accept friend request from other users in my Django social site

unable to accept friend requests in my web app below are the errors that I'm getting when I'm trying to accept the friend request. Environment: Request Method: GET Request URL: http://127.0.0.1:8000/users/friend-request/accept/5/ Django Version: 2.1 Python Version: …

03.12.2021
0
answers

How to link my Django form selection to filtered database values

I am configuring a web page using Django in which I would like my form's dropdown options to filter the database options based on the selection. There are four options: allElements, oldElements, newElements, and testElements. My problem is that while …

03.12.2021
1
answers

Django - Run all tests inside of "test" sub-folder

So I've been running tests using the command python manage.py test to run every test inside the test folder and I'd like to run all test in a subfolder of the test folder. So I tried python manage.py test <app …

03.12.2021
0
answers

Django virtual environment successfully installed. But when I run 'pip freeze' in command prompt it says 'No python at C drive'

Python is already installed and the version is 3.8. Could anyone help me? [1]: https://i.stack.imgur.com/44FSS.jpg![enter image description here](https://i.stack.imgur.com/kGWX3.jpg)

1 2 3 4 638 639