I am creating an jobsearch website in django. where jobseekers can find jobs and recruiters can post the jobs,

117 views Asked by At

I have three diffrent apps in my django project, Home, jobseeker and recruiter. and each app have different subdomain. Home => localhost:8000, jobseeker => jobseeker.localhost.8000, and for recruiter => recruiter.localhost:8000. i have an registration form in my Home app(localhost:8000) when i submitting the form i am getting..

Forbidden (403)
CSRF verification failed. Request aborted.

Help
Reason given for failure:

    Origin checking failed - null does not match any trusted origins.

how can i solve this?

here is my hosts.py file

from django_hosts import patterns, host

host_patterns = patterns('',
                         host(r'^(?:www\.)?$', 'Home.urls', name='perfectpesha'),
                         host(r'jobseeker', 'jobseeker.urls', name='jobseeker'),
                         host(r'recruiter', 'recruiter.urls', name='recruiter'),
                         )

here is my registration form

{% extends "layout.html" %}
{% load i18n %}
{% load hosts %}
{% load static %}
{% load tz %}

{% block content %}

<form class="form-horizontal" method="POST" action="{% host_url "jobseekerRegister" host "jobseeker" %}">

    {% csrf_token %}

    <div class="formrow">

        <input type="text" name="name" class="form-control" required="required"
               placeholder="Full Name" {% if form.name.errors %}style="border: 1px solid #FE0004"{% endif %}>


        {% if form.name.errors %}
            {% for error in form.name.errors %}
                <span class="help-block-error"> <strong>{{ error }}</strong></span>
            {% endfor %}
        {% endif %}

    </div>


    <div class="formrow">

        <input type="email" name="email" class="form-control" required="required"
               placeholder="Email" {% if form.email.errors %}style="border: 1px solid #FE0004"{% endif %}>


        {% if form.email.errors %}

                {% for error in form.email.errors %}
                    <span class="help-block-error"> <strong>{{ error }}</strong></span>
                {% endfor %}

        {% endif %}


    </div>


    <div class="formrow">

        <input type="number" name="mobile" class="form-control" required="required"
               placeholder="Mobile" {% if form.mobile.errors %}style="border: 1px solid #FE0004"{% endif %}>


        {% if form.mobile.errors %}

                {% for error in form.mobile.errors %}
                    <span class="help-block-error"> <strong>{{ error }}</strong></span>
                {% endfor %}

        {% endif %}


    </div>

    <div class="formrow">

        <input type="password" name="password" class="form-control" required="required"
               placeholder="Password" {% if form.password.errors %}style="border: 1px solid #FE0004"{% endif %}>

        {% if form.password.errors %}
                {% for error in form.password.errors %}
                   <span class="help-block-error"> <strong>{{ error }}</strong></span>
                {% endfor %}

        {% endif %}
    </div>


    <div class="formrow">

        <input type="password" name="password_confirmation" class="form-control"
               required="required" placeholder="Password Confirmation" {% if form.password_confirmation.errors %}style="border: 1px solid #FE0004"{% endif %}>

        {% if form.password_confirmation.errors %}

            {% for error in form.password_confirmation.errors %}
                <span class="help-block-error"> <strong>{{ error }}</strong></span>
            {% endfor %}

        {% endif %}
    </div>


    <div class="formrow">

        <textarea class="form-control" name="address" placeholder="address"></textarea>

    </div>


    <div class="formrow">


        <input type="checkbox" value="1" name="is_subscribed"
               checked=&quot;checked&quot;/>
        Subscribe to Newsletter

    </div>


    <div class="formrow">

        <input type="checkbox" value="1" name="terms_of_use"/>

        <a href="#">I accept Terms of Use</a>


    </div>

    <input type="submit" class="btn" value="Register">

</form>
{% endblock %}

and here is jobseeker url

path("register/", views.register, name="jobseekerRegister"),

my form is submitting from localhost:8000/login to jobseeker.localhost:8000/login but i am getting csrf error.

this is my settings.py file

ALLOWED_HOSTS = [env('HOST'), 'jobseeker.' + env('HOST'), 'recruiter.' + env('HOST')]

CSRF_TRUSTED_ORIGINS = ['http://' + env('HOST'), 'http://jobseeker.' + env('HOST'), 'http://recruiter.' + env('HOST')]

in .env file

HOST='localhost'

please help me.....

0

There are 0 answers