django

Django admin csrf token not set

Django admin csrf token not set Question: I have a Django project working locally with login to the admin portal working. Once the project has been deployed to our development environment the pages that do not require CSRF authentication are viewable, but the admin portal returns a CSRF token error when attempting to login. Error …

Total answers: 2

how to use same url and class for put, get, post, delete functions in drf class base api

how to use same url and class for put, get, post, delete functions in drf class base api Question: in my views file I want to have this logic: class Articles(APIView): def get(self, reqeust, id): #logic def put(self, request, id): #logic def post(self, requst, id): #logic def delete(self, request, id): #logic and I want handle …

Total answers: 1

I am trying to import views.py to urls.py using from . import views but I keep getting an import error

I am trying to import views.py to urls.py using from . import views but I keep getting an import error Question: from django.contrib import admin from django.urls import path from . import views urlpatterns = [ path(‘admin/’, admin.site.urls), path("", views.home), path("predict/", views.predict), path("predict/result", views.result) the traceback is File "C:UsersuserPycharmProjectsDiabetes PredictionDiabetes_PredictionDiabetes_Predictionurls.py", line 19, in from . …

Total answers: 2

ModuleNotFoundError: No module named 'view'

ModuleNotFoundError: No module named 'view' Question: My filetree looks like this: So in my urls.py folder, I have the following code: from django.urls import path from view import views #URLConf urlpatterns = [ path(‘hello/’, views.say_hello) ] The error I get when I am trying to python manage.py runserver is File "/Users/swathikumar/Desktop/storefront/playground/urls.py", line 3, in from …

Total answers: 4

Django value has an invalid format. It must be in YYYY-MM-DD HH:MM[:ss[.uuuuuu]][TZ] format.']

Django value has an invalid format. It must be in YYYY-MM-DD HH:MM[:ss[.uuuuuu]][TZ] format.'] Question: I have a Django project. I want to press button and date time save to database, but there is an error. File view.py def confirm_order(request, pk): get_emp = get_object_or_404(Employee, pk=pk) if request.method == ‘POST’: new_end_date = request.POST[‘new_date’] get_emp.end_date = new_end_date get_emp.save() …

Total answers: 1

Running sphinx-build leads to AttributeError: 'Values' object has no attribute 'link_base'

Running sphinx-build leads to AttributeError: 'Values' object has no attribute 'link_base' Question: I have a Django 4.2 project and wish to run Sphinx to generate the docs. When I run sphinx-build -b html docs_source/ docs/ I got the following error: Exception occurred: File "C:ProgramDataAnaconda3envsdjango_3_8Libsite-packagesdjangocontribadmindocsutils.py", line 116, in _role inliner.document.settings.link_base, ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ AttributeError: ‘Values’ object has no …

Total answers: 1

Order Django queryset by value closest to 0

Order Django queryset by value closest to 0 Question: I have a queryset that is returning a list of entries that are tied for the lead in a contest… leaders = ContestEntry.objects.filter(name=game, wins=wins) After I get this data I need to put them in order by a second field (‘difference’) as a tie breaker. The …

Total answers: 2

How can I send Email in Django Function based view using Brevo API

How can I send Email in Django Function based view using Brevo API Question: I have developed a Django web application and integrated sending customize email using Brevo formally known as SendinBlue. My settings.py file for sending emails is configured fine, because I am able to receive Password reset email but I am unable to …

Total answers: 1

Django model with uuid5 primary key

Django model with uuid5 primary key Question: I have a problem to define Django model where the Primary Key is UUID5 that base on model fields. Here is what I have got already. class Place(models.Model): uuid = models.UUIDField(primary_key=True, default=uuid.uuid5(‘PLACE_UUID_NAMESPACE’, ‘{}{}{}’.format(self.city, self.zip, self.country))) city = models.CharField(max_length=24, blank=True, null=True) zip = models.CharField(max_length=6, blank=True, null=True) country = CountryField(default=’US’) …

Total answers: 2