Skip to content

Commit

Permalink
add django-cors-headers
Browse files Browse the repository at this point in the history
  • Loading branch information
d2avids committed Jun 15, 2024
1 parent 90ee422 commit c357a37
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 5 deletions.
8 changes: 5 additions & 3 deletions backend/backend/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'corsheaders',
'rest_framework',
'rest_framework.authtoken',
'drf_spectacular',
Expand All @@ -48,6 +49,7 @@
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',
Expand Down Expand Up @@ -216,23 +218,23 @@
CELERY_TASK_SERIALIZER = 'json'
CELERY_RESULT_SERIALIZER = 'json'

CORS_ALLOW_ALL_ORIGINS = True if os.getenv('CORS_ALLOW_ALL_ORIGINS', False) == 'True' else False
CORS_ORIGIN_WHITELIST = [
'http://localhost:3000',
'http://localhost:8080',
'http://127.0.0.1:8080',
'http://localhost:80',
'http://localhost',
'http://31.129.98.70/',
'http://31.129.98.70',
]

CSRF_TRUSTED_ORIGINS = [
'http://localhost:3000',
'http://localhost:8080',
'http://localhost:80',
'http://127.0.0.1:8080',
'http://localhost',
'https://127.0.0.1',
'http://31.129.98.70/',
'http://31.129.98.70',
]

# EMAIL BACKEND
Expand Down
6 changes: 4 additions & 2 deletions backend/users/models.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from decimal import Decimal

from django.contrib.auth.models import AbstractUser
from django.core.exceptions import ValidationError
from django.core.validators import (MinValueValidator, MaxValueValidator,
Expand Down Expand Up @@ -180,8 +182,8 @@ class ChildrenGroup(models.Model):
max_digits=4,
decimal_places=2,
validators=[
MinValueValidator(1.0),
MaxValueValidator(99.0),
MinValueValidator(Decimal('1.00')),
MaxValueValidator(Decimal('99.00')),
],
error_messages={
'invalid': 'Средний возраст должен быть от 1 до 99'
Expand Down
81 changes: 81 additions & 0 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ readme = "README.md"

[tool.poetry.dependencies]
python = "^3.12"
django-cors-headers = "^4.3.1"


[build-system]
Expand Down
5 changes: 5 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
asgiref==3.8.1 ; python_version >= "3.12" and python_version < "4.0"
django-cors-headers==4.3.1 ; python_version >= "3.12" and python_version < "4.0"
django==5.0.6 ; python_version >= "3.12" and python_version < "4.0"
sqlparse==0.5.0 ; python_version >= "3.12" and python_version < "4.0"
tzdata==2024.1 ; python_version >= "3.12" and python_version < "4.0" and sys_platform == "win32"

0 comments on commit c357a37

Please sign in to comment.