In django web apps csrf.js returning 404 , "detail": "CSRF Failed: CSRF token missing or incorrect."

Postbox 1 Reputation point

Hi all,
Refer my application logs below, all the below files are throwing 404. But I can find these file in virtual environment via ssh.

2021-06-25T11:05:07.379075285Z Not Found: /static/rest_framework/js/jquery-3.5.1.min.js
2021-06-25T11:05:07.438874597Z Not Found: /static/rest_framework/css/default.css
2021-06-25T11:05:07.487314611Z Not Found: /static/rest_framework/css/prettify.css
2021-06-25T11:05:07.538870153Z Not Found: /static/rest_framework/js/ajax-form.js
2021-06-25T11:05:07.576363173Z Not Found: /static/rest_framework/js/csrf.js
2021-06-25T11:05:07.644366155Z Not Found: /static/rest_framework/js/bootstrap.min.js
2021-06-25T11:05:07.682412381Z Not Found: /static/rest_framework/js/prettify-min.js
2021-06-25T11:05:07.727584367Z Not Found: /static/rest_framework/js/default.js
2021-06-25T11:05:07.816163725Z Not Found: /static/rest_framework/js/jquery-3.5.1.min.js
2021-06-25T11:05:07.873995020Z Not Found: /static/rest_framework/js/ajax-form.js
2021-06-25T11:05:07.946735842Z Not Found: /static/rest_framework/js/csrf.js
2021-06-25T11:05:08.007143459Z Not Found: /static/rest_framework/js/bootstrap.min.js
2021-06-25T11:05:08.070873704Z Not Found: /static/rest_framework/js/prettify-min.js
2021-06-25T11:05:08.131653725Z Not Found: /static/rest_framework/js/default.js

Due to this issue , I am unable to pass CSRF token to post/put operation

Azure App Services
Azure App Services
A feature of Azure App Service used to create and deploy scalable, mission-critical web apps.
4,574 questions
Azure Active Directory
Azure Active Directory
An Azure enterprise identity service that provides single sign-on and multi-factor authentication.
13,602 questions
No comments
{count} votes

1 answer

Sort by: Most helpful
  1. ajkuma 14,176 Reputation points Microsoft Employee

    @Postbox , Apologies for the delay in responding here.

    Oryx runs collectstatic on your behalf unless you specify the DISABLE_COLLECTSTATIC env var. Make sure you've set STATIC_ROOT in


      STATIC_ROOT = './static/'  
    Or having STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')  

    To host static files in your web app, add the whitenoise package to requirements.txt and the configuration for it to

    Note: It will depend on the Django version, always try the latest version.

      # requirements.txt  

    You can find a Django working sample with static files for Web Apps On Linux here.

    Kindly check this doc for the recommended configuration -

    Please let us know how it goes and I'll follow-up further.