V
V
vasia9722018-10-10 17:58:15
Django
vasia972, 2018-10-10 17:58:15

How to send post requests to a subdomain?

There is a project with two subdomains: forum.site.com and games.site.com, when sending an ajax post request from one subdomain to another server, it is rejected, since csrf and sessionid tokens are not sent from cookies. Inside one domain, the code works properly.
Subdomains have utilities that are useful to me, I would like to use them without duplicating urls, if this is not possible, then tell me the correct
settings.py architecture

SESSION_COOKIE_DOMAIN = 'site.com'
CSRF_COOKIE_DOMAIN = 'site.com'
CSRF_COOKIE_NAME = 'csrftoken'
CSRF_TRUSTED_ORIGINS = ['games.site.com', 'forum.site.com']

MIDDLEWARE = [
    'corsheaders.middleware.CorsMiddleware',
    'corsheaders.middleware.CorsPostCsrfMiddleware',
    ...,
    ...,
]

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Decadal, 2018-10-10
@vasia972

Are you sure you tried googling?
dig in the direction of Access-Control-Allow-Origin - this header should return the server that is being accessed via Ajax. The header value must be source or * - valid sources from which the request can be made

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question