Facing CORS issue in after deployment
using Django Rest Framework using Swagger
After running API's in swagger I am getting this Error in deployment
Error is
**Failed to fetch.
Possible Reasons:
CORS
Network Failure
URL scheme must be "http" or "https" for CORS request.**
it was working fine in local
My settings.py -
Settings.py
-
-
INSTALLED_APPS = [
-
" ADDED ALL APPS"
-
'corsheaders',
-
'
-
-
]
-
-
MIDDLEWARE = [
-
'django.middleware.security.SecurityMiddleware',
-
'django.contrib.sessions.middleware.SessionMiddleware',
-
'corsheaders.middleware.CorsMiddleware',
-
'django.middleware.common.CommonMiddleware',
-
'django.middleware.csrf.CsrfViewMiddleware',
-
'django.contrib.auth.middleware.AuthenticationMiddleware',
-
'django.contrib.messages.middleware.MessageMiddleware',
-
'django.middleware.clickjacking.XFrameOptionsMiddleware',
-
'django.middleware.csrf.CsrfViewMiddleware',
-
'corsheaders.middleware.CorsPostCsrfMiddleware',
-
"django.middleware.security.SecurityMiddleware",
-
"whitenoise.middleware.WhiteNoiseMiddleware",
-
]
-
-
CORS_ALLOW_METHODS = [
-
'DELETE',
-
'GET',
-
'OPTIONS',
-
'PATCH',
-
'POST',
-
'PUT',
-
]
-
CORS_ALLOW_HEADERS = [
-
"accept",
-
"accept-encoding",
-
"authorization",
-
"content-type",
-
"dnt",
-
"origin",
-
"user-agent",
-
"x-csrftoken",
-
"x-requested-with",
-
]
-
-
CORS_ALLOW_ALL_ORIGINS = True
-
-
CORS_ALLOWED_ORIGINS = [
-
"HERE MY DOMAIN"
-
]
-
-
-
-
-
1 11581
CORS (Cross-Origin Resource Sharing) issues occur when a web application hosted on one domain tries to access resources (APIs, fonts, images, etc.) on another domain. CORS is a security mechanism implemented by web browsers to prevent cross-origin requests unless explicitly allowed.
To resolve CORS issues in Django Rest Framework (DRF) after deployment and when using Swagger, you can follow these steps:
1-Install the django-cors-headers package by running the following command.
2-Add 'corsheaders' to the INSTALLED_APPS setting in your Django project's settings.py file
3-Define the CORS origin settings in your settings.py file. You can set it to allow all origins using the CORS_ORIGIN_ALLOW_ALL option, or specify specific origins using the CORS_ORIGIN_WHITELIST option
4-Restart your Django server to apply the changes.
By following these steps, you should be able to resolve CORS issues when using Django Rest Framework with Swagger. Make sure to adjust the CORS origin settings according to your specific deployment configuration and security requirements.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Ilias Lazaridis |
last post by:
I have implemented a simple schema evolution support for django, due to
a need for a personal project. Additionally, I've provided an Audit:
http://case.lazaridis.com/wiki/DjangoAudit
As a...
|
by: Ray |
last post by:
I just moved to another company that's mainly a Java/.NET shop. I was
happy to find out that there's a movement from the grassroot to try to
convince the boss to use a dynamic language for our...
|
by: Dave U. Random |
last post by:
http://snipr.com/PracticalDjango
|
by: K |
last post by:
Hello everyone,
I understand that urllib and urllib2 serve as really simple page
request libraries. I was wondering if there is a library out there
that can get the HTTP requests for a given...
|
by: Aspersieman |
last post by:
On Wed, 05 Nov 2008 08:35:23 +0200, 3000 billg <billg3000@hos.twgg.org>
wrote:
Hi
Excellent choice :)
|
by: imhomer |
last post by:
I met this problem (Django base.py: 'str' object is not callable) when I go through a Django tutorial:
photo/models.py:
from django.db import models
from django.contrib.auth.models import User...
|
by: samvb |
last post by:
Hey Fellas,
I am seriously in despair. I have a CI driven app in domaina.com. I need to send cross domain request to a SINGLE controller in it from domainb.com. It will be an ajax call using POST...
|
by: samvb |
last post by:
Hi,
We have a DRF backend API and two front-end applications: a CRUD and a report server. Currently, we have issue with CORS:
These are the domains:
sever.com:8098 == >backend
and front...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |