Django community: RSS
This page, updated regularly, aggregates Django Q&A from the Django community.
-
summernote rtl plugin giving error of "can only concatenate tuple (not "set") to tuple"
Hi im using the summernote on my django application and want to allow arabic to be written,I seen this plugin, but when i add the js file to the summernote config I receive the following error "can only concatenate tuple (not "set") to tuple" https://github.com/virtser/summernote-rtl-plugin Setting.py SUMMERNOTE_CONFIG = { # Using SummernoteWidget - iframe mode, default 'iframe': True, # To use external plugins, # Include them within `css` and `js`. 'js': { '../guide/static/summernote/summernote-ext-rtl.js' }, # You can put custom Summernote settings 'summernote': { 'disableResizeEditor': False, # Change editor size 'width': '100%', 'border':'0px', 'height':'545px', 'minHeight': 'null', 'maxHeight': 'null', # Use proper language setting automatically (default) 'lang': None, 'toolbar': [ ['style', ['bold', 'italic', 'underline']], ['fontsize', ['fontsize']], ['color', ['color']], ['para', ['ul', 'ol', 'paragraph']], ['picture'], ['video'], ['table'], ['hr'], ['ltr','rtl'], ], }, } -
Many-To-Many relationships with Postgresql and accesing them
I'm working with a Posgtgresql database about movies, and I have a few Many-to-Many relationships like the following one: There's a table with movies and each movie has some keywords, as well as two movies can have the same keyword. For that we have three tables: movies, keywords, and movies_keywords. The table named movies is self-explanatory, it contains the title, an ID and many attributes that a movie has. The table movies_keywords has two columns: a movie ID and a keyword ID. This is like the "middle" that connects the two other tables. Lastly, the table keywords contains a keyword ID and the corresponding keyword. The problem is the following: I'm working with Django and I need to access all the keywords for one movie, but they're not directly connected, there's this middle point that doesn't let me access the names. Do you have any idea how can this be achieved? Thanks in advance! -
Django change change default profile picture by gender
I want to change default profile picture depen on gender.I choose Male in Register Form but always display "default_f.png". models.py GENDER_CATEGORY = ( ('U','Undefined'), ('F','Female'), ('M','Male') ) class Profile(models.Model): user = models.OneToOneField(User,on_delete=models.CASCADE) image = models.ImageField(upload_to="profile_pics",verbose_name="") cover_image = models.ImageField(default="default_cover.jpg",upload_to="cover_pics",verbose_name="") bio = models.CharField(max_length=160,null=True,blank=True) location = models.CharField(max_length=30,null=True,blank=True) birth_date = models.DateField(null=True,blank=True) follow = models.ManyToManyField(User,related_name="follower") date_created = models.DateTimeField(default=timezone.now) gender = models.CharField(choices=GENDER_CATEGORY,max_length=2) Signals So I try this if statement but always show default_f.png.I change pre_save to post_save but it didn't change. def post_save_avatar(sender, instance, *args, **kwargs): if not instance.image: if instance.gender == 'M': instance.image="default_m.jpg" else: instance.image = "default_f.png" print(instance.gender) pre_save.connect(post_save_avatar, sender=Profile) def create_profile(sender, **kwargs): if kwargs['created']: user_profile = Profile.objects.create(user=kwargs['instance']) post_save.connect(create_profile,sender=User) forms.py class RegisterForm(UserCreationForm): email = forms.EmailField() class Meta: model = User fields = ('username','email','password1','password2') class ProfileRegisterForm(forms.ModelForm): class Meta: model = Profile views.py def register(request): if request.method == "POST": form = RegisterForm(request.POST) p_form = ProfileRegisterForm(request.POST) if form.is_valid() and p_form.is_valid(): user = form.save() user.refresh_from_db()#load the profile instance create by the signal p_form = ProfileRegisterForm(request.POST,instance=user.profile) p_form.full_clean() p_form.save() # username = form.cleaned_data.get('username') return redirect('login') else: form = RegisterForm() p_form = ProfileRegisterForm() context = { 'form':form, 'p_form':p_form } fields = ['bio','gender'] -
Images in Django aren't loading even though they're stored locally
With the code I have currently, my images used to load but now they don't and I can't figure out why. Within my Artist model, I have included an ImageField. This lets me upload an image and store it in a directory called 'artists' in my media directory. class Artist(models.Model): name = models.CharField(max_length=40) genre = models.CharField(max_length=20) location = models.CharField(max_length=20) bio = models.TextField() photo = models.ImageField(upload_to='artists', null=True, blank=True) def __str__(self): return self.name As you can see below, my image 'fontaines.png' has been uploaded and stored in /media/artists/. ├── db.sqlite3 ├── manage.py ├── media │ ├── artists │ │ └── fontaines.png ├── mysite │ ├── __init__.py │ ├── __pycache__ │ │ ├── __init__.cpython-38.pyc │ │ ├── settings.cpython-38.pyc │ │ ├── urls.cpython-38.pyc │ │ └── wsgi.cpython-38.pyc │ ├── asgi.py │ ├── settings.py │ ├── static │ │ └── main.css │ ├── templates │ │ └── base.html │ ├── urls.py │ └── wsgi.py └── pages ├── __init__.py ├── __pycache__ │ ├── __init__.cpython-38.pyc │ ├── admin.cpython-38.pyc │ ├── apps.cpython-38.pyc │ ├── forms.cpython-38.pyc │ ├── models.cpython-38.pyc │ ├── urls.cpython-38.pyc │ └── views.cpython-38.pyc ├── admin.py ├── apps.py ├── forms.py ├── migrations │ ├── 0001_initial.py │ ├── 0002_artist.py │ ├── __init__.py │ └── __pycache__ │ ├── 0001_initial.cpython-38.pyc │ … -
Path is not matching
I have started learning Django and I was watching this lecture (till starting 20 minutes) and following the instructions but I am getting the error as : Page not found (404) Request Method: GET Request URL: http://127.0.0.1:8000/hello Using the URLconf defined in lecture3.urls, Django tried these URL patterns, in this order: admin/ The current path, hello, didn't match any of these. You're seeing this error because you have DEBUG = True in your Django settings file. Change that to False, and Django will display a standard 404 page. After running python3 manage.py runserver My settings.py file in "lecture3" app is : # Application definition INSTALLED_APPS = [ 'hello', 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', ] and some other content. views.py file in "hello" app is : from django.http import HttpResponse from django.shortcuts import render # Create your views here. def index(request): return HttpResponse("Hello World!") urls.py file in "hello" app is : from django.urls import path from . import views urlpatterns=[ path("",views.index, name="index") ] urls.py file in "lecture3" app is : from django.contrib import admin from django.urls import include, path urlpatterns = [ path('admin/', admin.site.urls), path('/hello/', include('hello.urls')) ] I have checked similar questions here but my problem was not resolved. Can … -
ValueError at /pembayaran/ ModelForm has no model class specified
from django import forms from django.forms import ModelForm from .models import pembayaranform class pembayaran(ModelForm): class Meta: models = pembayaranform fields='__all__' what's wrong? -
Reorganise a Django Model for django_tables2
I am trying to build a app that displays some subset of a database I have, however it is not exactly in the format I want to display. e.g. The current data (and model) is organsed as such: id value a1 3 a2 3 a3 4 b1 5 b2 4 b3 4 But I want to display it as: id a b 1 3 5 2 3 4 3 4 4 I can easily make this change if I switch to pandas dataframe but this issue suggests django_tables2 can't do this. Are there other options I can explore? Below are my models, tables, and views file. The columns in the example relate to Parameter_ID and Forms. models.py class Forms(models.Model): id = models.TextField(db_column='ID', blank=True, null=False, primary_key=True) # Field name made lowercase. local_id = models.IntegerField(db_column='Local_ID', blank=True, null=True) # Field name made lowercase. language_id = models.TextField(db_column='Language_ID', blank=True, null=True) # Field name made lowercase. parameter_id = models.TextField(db_column='Parameter_ID', blank=True, null=True) # Field name made lowercase. value = models.TextField(db_column='Value', blank=True, null=True) # Field name made lowercase. form = models.TextField(db_column='Form', blank=True, null=True) # Field name made lowercase. segments = models.IntegerField(db_column='Segments', blank=True, null=True) # Field name made lowercase. comment = models.TextField(db_column='Comment', blank=True, null=True) # Field name made lowercase. … -
How to Handle CSRFToken Authenticity with Django REST and React.js Relation?
I am creating a Django REST project. I created a custom user model in which I used rest-knox for token authentication. For the login and register user endpoints I used custom views where I authenticate the user's by their knox token. For password_change endpoint I used django auth's views. Here is the problem I am facing: When I try password_change endpoint in browsable API; it redirects me again to login page and does nothing. However Knox token for the user is created and returned in JSON. When I try the endpoint in Postman it gives CSRF token error since I cannot get the CSRF token. I tried to create my own front-end page for changing password and sometimes the 'csrftoken' was returned in cookie table of chrome but not all the time. Since I get the user token with JSON response I set it to cookies on React.js and reach anytime I want. Yet, get method of react-cookie doesn't work for csrftoken and it is being set as undefined. Finally I tried to use axios library for my post request and set default header for 'csrftoken' but couldn't see any results. The front-end 'localhost:3000/change_password/' page just redirects to itself by … -
Django 2.0 - fail to load in tests fixtures i made with dumpdata
Basically, it seems i have the same problem elaborated in this question here. However, in that question they did not elaborate about the solution.. only worte you need to change the encoding of the file which Django generates itself to UTF-8. However, as commented there, it's not solving the problem (i export the file in XML which is already in UTF-8 format). I have Mysql 5.7 db. On one of my tables i i have column with charset - 'utf8mb4'. My django project and db works fine. However, when i try to load fixtures i made with datadump on tests, i get this error msg: could not load web.Off(pk=672): (1366, "Incorrect string value: '\xC2\x96Lag ...' for column 'name' at row 1") my datadump statement: python3 manage.py dumpdata --format=xml -o web/fixtures/tests.xml my tests.py fixtures statement: class WebPagesTests(TestCase): fixtures = ['tests'] i tried changing the settings t allow 'utf8mb4' but it didn't worked: DATABASES = { 'default': { 'ENGINE': 'django.db.backends.mysql', 'NAME': 'mydb', .... 'HOST': 'db', 'PORT': '3306', 'OPTIONS': {'charset': 'utf8mb4'}, 'TEST_CHARSET': 'utf8mb4', } } It's worth mentioning that i getting no errors when i try to load this same fixture with loaddata command (not in tests.py): python3 manage.py loaddata -
Why is Web Deploy code python django rest framework
"detail": "JSON parse error - Expecting property name enclosed in double quotes: line 11 column 5 (char 300)" } -
How to implicitly assign value to DRF serializer read_only field?
Example code # models.py class Profile(models.Model): first_name = models.CharField(max_length=64) last_name = models.CharField(max_length=64) ... class Photo(models.Model): image = models.ImageField(upload_to='photos') profile = models.ForeignKey('Profile', on_delete=models.CASCADE, related_name='photos') ... # serializers.py class ProfileSerializer(serializers.ModelSerializer): photos = serializers.HyperlinkedRelatedField(many=True, view_name='photo-detail', read_only=True) class Meta: model = Profile fields = '__all__' class PhotoSerializer(serializers.ModelSerializer): # How to assign this implicitly from view? profile = PrimaryKeyRelatedField(read_only=True) class Meta: model = Face fields = '__all__' My solution # views.py class ProfileViewSet(viewsets.ModelViewSet): queryset = Profile.objects.all() serializer_class = ProfileSerializer @action(methods=['GET', 'POST'], detail=True, serializer_class=FaceSerializer) def photos(self, request, *args, **kwargs): profile = self.get_object() if request.method == 'GET': ... elif request.method == 'POST': serializer = self.get_serializer(data=request.data) serializer.is_valid() # accessing validated_data # explicitly set profile read_only field serializer.validated_data['profile'] = profile self.perform_create(serializer) return Response(serializer.data) Example call curl -X POST http://localhost:8000/profiles/4/photos/ --form image=@photo_image.jpg Expected behavior HTTP 200 OK Allow: GET, POST, HEAD, OPTIONS Content-Type: application/json Vary: Accept { "id": 123, "profile": 4, "image": "http://localhost:9000/media/photos/photo_image.jpg", .... } When passing photo image to endpoint /profile/<int:pk>/photos/, Photo's (read_only=True) profile field have been set by extracted <int:pk> view parameter. Question Is there more elegant way to achieve this? I don't feel comfortable accessing serializer.validated_data and explicitly set profile value... -
problem when deploying vuejs app on heroku
I have a vuejs app that calling api from django website. I've already deployed django app on heroku successful but when I deploy vuejs and have access to my website. Something went wrong and when I looked at logs, some issues occur. Here is the logs 2020-04-19T14:49:31.711749+00:00 app[web.1]: sh: 1: vue-cli-service: not found 2020-04-19T14:49:31.716381+00:00 app[web.1]: npm ERR! code ELIFECYCLE 2020-04-19T14:49:31.716381+00:00 app[web.1]: npm ERR! syscall spawn 2020-04-19T14:49:31.716382+00:00 app[web.1]: npm ERR! file sh 2020-04-19T14:49:31.716509+00:00 app[web.1]: npm ERR! errno ENOENT 2020-04-19T14:49:31.717484+00:00 app[web.1]: npm ERR! frontend@0.1.0 serve: `vue-cli-service serve` 2020-04-19T14:49:31.717565+00:00 app[web.1]: npm ERR! spawn ENOENT 2020-04-19T14:49:31.717683+00:00 app[web.1]: npm ERR! 2020-04-19T14:49:31.717772+00:00 app[web.1]: npm ERR! Failed at the frontend@0.1.0 serve script. 2020-04-19T14:49:31.717842+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above. 2020-04-19T14:49:31.725202+00:00 app[web.1]: 2020-04-19T14:49:31.725472+00:00 app[web.1]: npm ERR! A complete log of this run can be found in: 2020-04-19T14:49:31.725649+00:00 app[web.1]: npm ERR! /app/.npm/_logs/2020-04-19T14_49_31_718Z-debug.log 2020-04-19T14:49:31.737139+00:00 app[web.1]: npm ERR! code ELIFECYCLE 2020-04-19T14:49:31.737481+00:00 app[web.1]: npm ERR! errno 1 2020-04-19T14:49:31.739147+00:00 app[web.1]: npm ERR! frontend@0.1.0 start: `npm run serve` 2020-04-19T14:49:31.739368+00:00 app[web.1]: npm ERR! Exit status 1 2020-04-19T14:49:31.739629+00:00 app[web.1]: npm ERR! 2020-04-19T14:49:31.739829+00:00 app[web.1]: npm ERR! Failed at the frontend@0.1.0 start script. 2020-04-19T14:49:31.742569+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There … -
Easy way to encrypt model data in Django?
I am using mySQL database in my Django project and I want to make the .idb file that database creates to store data unreadable. I want that file to be unreadable. I don't need big and advance encryption, simple can work. Thank You. -
Django ManyToManyField is updated in admin but not through the CreateView (user side) form
I am trying to make a tag function for a post with ManyToManyField in django. If I add tags through admin, they are updated properly, but through the createview form, it is not updated. Below are the code of the related classes in model.py class Tag(models.Model): name = models.CharField(max_length=50, unique=True) def __str__(self): return self.name class Post(models.Model) : title = models.CharField( max_length=200, validators=[MinLengthValidator(2, "Title must be greater than 2 characters")] ) picture = models.BinaryField(null=True, blank=True, editable=True) content_type = models.CharField(max_length=256, null=True, blank=True, help_text='The MIMEType of the file') text = models.TextField() owner = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE) #foreign key from django setting category = models.ForeignKey(Category, blank=True, null=True, on_delete=models.SET_NULL) tags = models.ManyToManyField(Tag, blank=True) created_at = models.DateTimeField(auto_now_add=True) updated_at = models.DateTimeField(auto_now=True) # Shows up in the admin list def __str__(self): return self.title And, CreateView class in view.py class PostCreateView(LoginRequiredMixin, View): template = 'cfis/post_form.html' success_url = reverse_lazy('cfis:all') def get(self, request, pk=None) : form = PostCreateForm() ctx = { 'form': form } return render(request, self.template, ctx) def post(self, request, pk=None) : form = PostCreateForm(request.POST, request.FILES or None) if not form.is_valid() : ctx = {'form' : form} return render(request, self.template, ctx) # Add owner to the model before saving pic = form.save(commit=False) pic.owner = self.request.user pic.save() return redirect(self.success_url) Lastyl, form class … -
Django display value text in formset
I wanna display the text value of a foreign key on the templante, in a way that the user cannot change it. Template: {% for form in formset %} <div class=""> {% for field in form %} {{ field }} {% endfor %} </div> {% endfor %} HTML render: <select name="form-0-semestre_solicitacao" id="id_form-0-semestre_solicitacao"> <option value="">---------</option> <option value="5">2020/1</option> <option value="4">2019/2</option> <option value="3" selected="">2019/1</option> <option value="2">2018/2</option <option value="1">2018/1</option> </select> I tried {{ field.initial }} and {{ field.value }} but it displays 3 and i would like it to display the text: 2019/1 -
Possible to create ArrayField for Django SQLite3 default DB?
I am working on my first Django project and right now I want the ability for the user to add multiple items to a model. It will look something like this in the admin panel. Expected Values [______________] + [______________] [______________] Each time they click the "+" it will open another line for them to add anything. From what I have came across so far is ArrayField is possibly what I want. However it seems that is not for the default Django DB SQLite3. I am trying to find a way to do what I want, while staying on SQLite3. Is it worth staying on SQLite3? Does switching to Postgres make what I want possible? Thanks -
How to override help_text and label for password form in django
I have the following form in my forms.py. For some reason the override of label and help_text for username field WORKS and (both) the password fields doesn't. class CreateUserForm(UserCreationForm): class Meta: model = User fields = ['username', 'password1', 'password2'] labels = { 'username': 'My Username Label', 'password1': 'My Password1 Label', 'password2': 'My Password2 Label', } help_texts = { 'username': 'My username help_text', 'password1': 'My password1 help_text', } When rendered the default django label/help_texts are showed for password fields: Your password can’t be too similar to your other personal information. Your password must contain at least 8 characters. ... I've already read those answers, but they weren't helpful: Q1 Q2 Q3 I've also read the docs, and there is a note here (green note lowering the page) that seems to be related, but I don't really understand it. It mentions Fields defined declaratively, which I'm not doing. Also wouldn't explain why it works for username and not for password1. -
AWS redis server config for django
I am following this tutorial and I am confused with the following code: CHANNEL_LAYERS = { 'default': { 'BACKEND': 'channels_redis.core.RedisChannelLayer', 'CONFIG': { "hosts": [(<REDIS ELASTICACHE HOSTNAME>, 6379)], }, }, } here, what 'REDIS ELASTICACHE HOSTNAME' refers to? I created redis instance using AWS ElastiCache, I didn't find 'HOSTNAME' anywhere in the AWS console of redis instance. I tried to replace it with the name of the instance but after testing it in the shell, I was unable to send message over the layer. The error in testing the layers was: File "C:\Users\Nouman\AppData\Local\Programs\Python\Python37\lib\socket.py", line 748, in getaddrinfo for res in _socket.getaddrinfo(host, port, family, type, proto, flags): socket.gaierror: [Errno 11001] getaddrinfo failed Can any body help? -
unable to connect to localhost in creating a django blog
I have written the following code in my urls.py : from django.conf.urls import url from django.contrib import admin from . import views urlpatterns = [ url(r'^admin/', admin.site.urls), url(r'^about/$', views.about), url(r'^$', views.homepage), ] and I created a views.py in my project folder and wrote the following code in it: from django.http import HttpResponse def homepage(request): return HttpResponse("homepage") def about(request): return HttpResponse('about') but when i use 127.0.0.1:800 for seeing my changes in browser i ocuured with unabling to connect and my internet connection does not have any problem what should I do? -
How do I use operators in Django {% if %} template tag?
so I'm trying to do simple calculation as my condition statement in {% if %}{% endif %} tag in Django. But somehow it doesn't work. Here's my code : {% for i in range %} {% if i/2 != 1 %} <!- Do something -> {% elif i/2 == 1 %} <!- Something else -> {% endif %} {% endfor %} I keep getting error that says "Could not parse the remainder: '/2' from 'i/2'" So there must be another way of using the operators in if statement, but I can't figure out what that is. I would very much appreciate your help! :) -
how to validate field already exist on form update
I add a validation on form.py to exclude the same record at the time of update so I check the username already exist or not, but self.instance.pk is getting None. I know there are also another way to do this but I want to know why self.instance.pk did not work, I will use this approach to other Forms also so I need to fix this using self.instance.pk here is my code so could you please review the code what is I am missing and why self.instance.pk not working. forms.py from django import forms from .models import CustomUser class UserForm(forms.ModelForm): password = forms.CharField(label='Password', widget=forms.PasswordInput) password2 = forms.CharField(label='Password confirmation', widget=forms.PasswordInput) class Meta: model = CustomUser fields = '__all__' exclude = ["is_admin", "is_verified", "last_login"] def clean_username(self): username = self.cleaned_data.get("username") print(self.instance.pk) user_obj = CustomUser.objects.exclude(pk=self.instance.pk).get(username=username) if user_obj: raise forms.ValidationError("username already exist") return username views.py def edit_profile(request): context = { "form": UserForm() } user_obj = request.user form = UserForm(instance=user_obj) context["form"] = form return render(request, "account/profile.html", context) -
int() argument must be a string, a bytes-like object or a number, not 'NoneType' - ecommerce
It says that int argument must be a string, however in trying to do that i received more errors. any solutions? i was following an online tutorial which doesn't seem to have this error, so not sure where mine is wrong. views.py def update_cart(request, slug): request.session.set_expiry(120000) try: qty = request.GET.get('qty') update_qty = True except: qty = '' update_qty = False try: the_id = request.session['cart_id'] except: new_cart = Cart() new_cart.save() request.session['cart_id'] = new_cart.id the_id = new_cart.id cart = Cart.objects.get(id=the_id) try: product = Product.objects.get(slug=slug) except Product.DoesNotExist: pass except: pass cart_item, created = CartItem.objects.get_or_create(cart=cart, product=product) if created: print("yes") if int(qty)== 0 and update_qty: cart_item.delete() elif update_qty: cart_item.quantity = qty cart_item.save() else: pass #if not cart_item in cart.items.all(): # cart.items.add(cart_item) #else: # cart.items.remove(cart_item) new_total = 0.00 for item in cart.cartitem_set.all(): line_total = float(item.product.price) * item.quantity new_total += line_total request.session['items_total'] = cart.cartitem_set.count() cart.total = new_total cart.save() return HttpResponseRedirect(reverse('cart')) urls.py from django.urls import path from . import views from carts import views as cart_views from orders import views as order_views urlpatterns = [ path('', views.home, name='fuisce-home'), path('subscription/', views.subscription, name='fuisce-subscription'), path('oneoff/', views.oneoff, name='fuisce-oneoff'), path('about/', views.about, name='fuisce-about'), path('contact/', views.contact, name='fuisce-contact'), path('cart/', cart_views.view, name='cart'), path('cart/<slug>/', cart_views.update_cart, name='update_cart'), path('cart/<int:id>', cart_views.remove_from_cart, name='remove_from_cart'), path('checkout/', order_views.checkout, name='checkout'), ] view.html {% extends "fuisce/base.html" %} … -
Is there a way I can run a web scraper on flask without blocking the server?
I have a web app written in Flask, a user will log in and input some search keywords, these keywords will be passed to a web scraper function I wrote and fetch the data, the web scraper function can take takes some minutes to return the data and render it to the user in a template, while the web scraper is running, the server is blocked, is there a way I can run the web scraper function in a separate thread or background and in some way render the data to the user without blocking the server, My code looks like this @app.route("/", methods=["GET", "POST"]) @login_required def home(): if request.method == "POST": search_phrase = request.form.get("search_term") data = run_scraper(search_phrase) for d in data: print(d) return render_template("index.html", results=data) else: return render_template("index.html") -
Django server deployment sucessful but shows some error on CMD
First I've created a Virtual environment... then I've created a Project called crm when I type python manage.py runserver Watching for file changes with StatReloader Performing system checks... System check identified no issues (0 silenced). April 19, 2020 - 19:03:25 Django version 3.0.5, using settings 'crm.settings' Starting development server at http://127.0.0.1:8000/ Quit the server with CTRL-BREAK. then when i go to this http://127.0.0.1:8000/ on Firefox I get the error (click the link to get the image) but the server runs well Can anyone explain me why i got this error?? -
Axios Post Request return Error 400 when that same data and url works with Postman (Django DRF ReactJS)
I am creating an application that uses Django as the backend, and ReactJS as the front end. I am using DRF for the api calls from ReactJS to Django, but am facing an issue with sending a post request. When i send a post request with the relevant data in JSON format using axios in ReactJS, it returns an error code of 400. However, when I copy that same JSON data and use it to send a post request in Postman, there was no error and the code was 201 (created). I am not too sure why there is this issue, and I have already set the neccessary settings in the Django settings.py to ensure that permission is granted (for testing purposes I just set it to 'allow all'). I managed to print out the error message behind the failed post request, but I do not really understand what the error message is talking about. If there is any other way to print out more error messages to sort of let me know where to start, please let me know, thanks! Any help is appreciated! REST_FRAMEWORK = { # Use Django's standard `django.contrib.auth` permissions, # or allow read-only access for …