Categories
Mastering Development

Django + React Able to create new user in database, but token-auth returns 400 bad request

So I have an app that I’m writing. It’s working, for the most part, so far. I only currently have a login and signup setup, with a ‘homepage’ that just has a logout button and some text on it so I can test. When I do signup, it posts the user to the database, but […]

Categories
Mastering Development

django-cors-headers not work in for patch method

INSTALLED_APPS = [ # default django apps ‘jazzmin’, ‘django.contrib.admin’, ‘django.contrib.auth’, ‘django.contrib.contenttypes’, ‘django.contrib.sessions’, ‘django.contrib.messages’, ‘django.contrib.staticfiles’, # Optional: Django admin theme (must be before django.contrib.admin) ‘rest_framework’, ‘rest_framework_simplejwt.token_blacklist’, ‘corsheaders’, ‘treebeard’, ‘UserAccount.apps.UseraccountConfig’, ‘CompanyInfo.apps.CompanyInfoConfig’, ‘Backup.apps.BackupConfig’, ‘FinancialPeriod’, ‘Inventory.apps.InventoryConfig’, ‘Product.apps.ProductConfig’, ] MIDDLEWARE = [ ‘corsheaders.middleware.CorsMiddleware’, ‘django.middleware.security.SecurityMiddleware’, ‘django.contrib.sessions.middleware.SessionMiddleware’, ‘django.middleware.common.CommonMiddleware’, ‘django.middleware.csrf.CsrfViewMiddleware’, ‘django.contrib.auth.middleware.AuthenticationMiddleware’, ‘django.contrib.messages.middleware.MessageMiddleware’, ‘django.middleware.clickjacking.XFrameOptionsMiddleware’, ] CORS_ORIGIN_ALLOW_ALL = True CORS_ALLOW_CREDENTIALS = False default_headers = ( […]

Categories
Development

django & javascript fetch(): CORS policy: No ‘Access-Control-Allow-Origin’ header is present

I am trying to make an ajax call. I am using django 2.2.5 and cors 3.1.0, but getting the following error messages in the browser console: Access to fetch at ‘http://my.domain.com/‘ from origin ‘http://127.0.0.1:8000‘ has been blocked by CORS policy: No ‘Access-Control-Allow-Origin’ header is present on the requested resource. If an opaque response serves your […]