ylliX - Online Advertising Network
Vertex AI - Antrophic and Mistral models: Why does it require Imegen access?

why is my server showing bad request in the log as soon as it starts and it was working fine a few days ago


I deployed my Django project on Render, but every time I try to access the root URL (/), I receive a 400 Bad Request error. I have confirmed that my settings are configured with ALLOWED_HOSTS and CSRF_TRUSTED_ORIGINS to include the Render domain (challo-backend-1.onrender.com). My Redis server is configured to 127.0.0.1:6379 for Channels, and Iā€™m using Django 5.1.2.

   ==> Your service is live šŸŽ‰
   127.0.0.1 - - [05/Nov/2024:16:41:12 +0000] "GET / HTTP/1.1" 400 143 "-" "Go-http-client/2.0"
   [2024-11-05 16:42:10 +0000] [95] [INFO] Handling signal: term
   [2024-11-05 16:42:10 +0000] [98] [INFO] Worker exiting (pid: 98)
   [2024-11-05 16:42:11 +0000] [95] [INFO] Shutting down: Master`  
   
"""
Django settings for challo project.

Generated by 'django-admin startproject' using Django 5.1.2.

For more information on this file, see
https://docs.djangoproject.com/en/5.1/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/5.1/ref/settings/
"""
import dj_database_url
from pathlib import Path
from datetime import timedelta
import os
from django.core.exceptions import ImproperlyConfigured

# Base Directory
BASE_DIR = Path(__file__).resolve().parent.parent

# Security settings (replace with your environment variable)
def get_secret_key():
    try:
        return os.environ['SECRET_KEY']
    except KeyError:
        raise ImproperlyConfigured("The SECRET_KEY setting must not be empty.")

SECRET_KEY = get_secret_key()

# Allowed Hosts and CSRF Trusted Origins
ALLOWED_HOSTS = ['challo-backend-1.onrender.com', '127.0.0.1', 'localhost']
CSRF_TRUSTED_ORIGINS = ['https://challo-backend-1.onrender.com']

# Channel Layers
CHANNEL_LAYERS = {
    'default': {
        'BACKEND': 'channels_redis.core.RedisChannelLayer',
        'CONFIG': {
            "hosts": [('127.0.0.1', 6379)],
        },
    },
}

# Installed Apps
INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'phonenumber_field',
    'rest_framework',
    'rest_framework_simplejwt',
    'users',
    'rides',
    'channels',
    'chat',
    'django_htmx',
    'corsheaders'
]

# Middleware
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 Settings
CORS_ALLOW_ALL_ORIGINS = True

# URL Configuration
ROOT_URLCONF = 'challo.urls'
WSGI_APPLICATION = 'challo.wsgi.application'
ASGI_APPLICATION = "challo.asgi.application"

# Database
DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': BASE_DIR / 'db.sqlite3',
    }
}

# Replace with environment variable for production
def get_dbKey():
    try:
        return os.environ['DATABASE_URL']
    except KeyError:
        raise ImproperlyConfigured("The DATABASE_URL setting must not be empty.")

DATABASE_URL = get_dbKey()
DATABASES['default'] = dj_database_url.parse(DATABASE_URL)

# Custom User Model
AUTH_USER_MODEL = 'users.CustomUser'

# REST Framework Configuration
REST_FRAMEWORK = {
    'DEFAULT_AUTHENTICATION_CLASSES': (
        'rest_framework_simplejwt.authentication.JWTAuthentication',
    )
}

# JWT Settings
SIMPLE_JWT = {
    'ACCESS_TOKEN_LIFETIME': timedelta(days=1),
    'REFRESH_TOKEN_LIFETIME': timedelta(days=1),
    'ROTATE_REFRESH_TOKENS': True,
    'BLACKLIST_AFTER_ROTATION': True,
    'UPDATE_LAST_LOGIN': True,
}

# Static Files
STATIC_URL = 'static/'

# Default Primary Key Field Type
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'



Source link

Leave a Reply

Your email address will not be published. Required fields are marked *