djangoproject.com djangoproject.com

How to return DRF Forms data in the POST

So I have a class based view views/users.py where the POST is supposed to send the data from the form to the serializer to validated it and if its alright create the user and return me the data, but for some reason it returns me a 404 bad request. Here's the view: class UserSignUpAPIView(APIView): """ User sign up API view. """ permission_classes = [AllowAny] renderer_classes =...

djangoproject.com djangoproject.com

How to serve static files with django-rest framework?

I am new to Django development and I want to deploy my project on Azure WebApp service. When I switch to DEBUG = False, I get this error : The resource from “http://127.0.0.1:8000/static/css/index.css” was blocked due to MIME type (“text/html”) mismatch (X-Content-Type-Options: nosniff). Yet, I followed the steps described in this post : ALLOWED_HOSTS and Django I understood Django does not serve the static files by itself,...

djangoproject.com djangoproject.com

Plotly Dash - Pattern Matching Callbacks Not Working Properly

here is some sample code that i have been trying to run from plotly dash's 'pattern matching callbacks examples page'. For the life of me, i cannot see what is wrong - the only error i get in the browser is Syntax Error - unexpected end of JSON input. I can see that the problem only occurs when i try to register the last callback with the pattern matching syntax. If it helps, I am using DjangoDash, so i can integrate dash with Django....

djangoproject.com djangoproject.com

DjangoREST - How can I make my view/serializer more efficient on the server?

I'm using a serializer to extract a specific object from my models, followed by using said object field as a parameter in URL's via requests. I'm not getting any errors and everything is working fine, however I think it can be optimized better and be more efficient on the server. serializer.py class BucketListExtraDataSerializer(serializers.ModelSerializer): bucket_return = serializers.SerializerMethodField() bucket_sectors =...

djangoproject.com djangoproject.com

Updating a django view with values from a js addin: How to trigger a change event and pass the values back to the view

I've got a form that has a dropdown for selecting the reporting period with the finish always being the current day and start determined by the dropdown selection of week, month, quarter or year. When the period form updates, it has an on change event that submits the form, the page recalculates with the new start date and refreshes. I want to replace this with something more precise and I've got xdsoft's period picker...

djangoproject.com djangoproject.com

Why won't the urls.py file in my Django project let me import this file?

I'm trying to import a function from a file in another directory into my urls.py file. I have included the directory in the settings.py file, ran the ./manage.py makemigrations & the ./manage.py migrate Django commands, and imported the function and the file into the urls.py file. Here is my current code: urls.py: from django.contrib import admin from django.urls import path from apps.accounts.urls import...

djangoproject.com djangoproject.com

how to take input from form submission and use it to display an entry using django

I'm trying to take the input from a form in Django and to then search storage and display any matches here is the code I have so far. views.py def search(request): input = request.GET.get('q') return render(request, "encyclopedia/search.html", { "entry": util.get_entry(input) == None, "display": util.get_entry(input) }) search.html {% extends "encyclopedia/layout.html" %} {% block title...

djangoproject.com djangoproject.com

Rename content_type and object_id in ContentTypeFramework

I want to create specific relation in my Django app. For doing this, I've chosen ContentTypeFramework and GenericForeignKey. In the django documentation there are not so much info about it. Here is it: There are three parts to setting up a GenericForeignKey: Give your model a ForeignKey to ContentType. The usual name for this field is “content_type”. Give your model a field that can store primary key values from the models...

djangoproject.com djangoproject.com

How to run django views.function() on everyday midnight 00:00 using scheduler or schedu

## below created scd.py import schedule import time from .views import * # Create your tests here. def job(): views.attendancetemplate() #a= urllib.request.urlopen(url='http://172.16.1.100:8000/tmp', ) ## this is working but still `enter code here` print("I'm working...") schedule.every().day.at("20:23").do(job) while True: schedule.run_pending() ...

djangoproject.com djangoproject.com

Reverse for 'posts' with keyword arguments '{'id': 106}' not found. 1 pattern(s) tried: ['posts/$']

I am building a BlogApp AND Everything is working fine BUT when i return redirect('mains:posts',id=post_id). It is showing me :- Reverse for 'posts' with keyword arguments '{'id': 106}' not found. 1 pattern(s) tried: ['posts/$'] views.py def post_like_dislike(request, post_id): post = get_object_or_404(Post, pk=post_id) # Like if request.GET.get('submit') == 'like': if request.user in...