question

Postbox-9811 avatar image
0 Votes"
Postbox-9811 asked JamesTran-MSFT commented

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

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-webappsazure-ad-authentication
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

ajkuma-MSFT avatar image
0 Votes"
ajkuma-MSFT answered JamesTran-MSFT commented

@Postbox-9811, Apologies for the delay in responding here.

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

// settings.py

   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 settings.py.

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

   # requirements.txt
   whitenoise==4.1.2


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

Kindly check this doc for the recommended configuration -https://github.com/microsoft/Oryx/wiki/Django-Tips

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

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

@Postbox-9811
I just wanted to check in and see if you had any other questions or if you were able to resolve this issue?

If you have any other questions, please let me know.
Thank you for your time and patience throughout this issue.


Please remember to "Accept Answer" if any answer/reply helped, so that others in the community facing similar issues can easily find the solution.

0 Votes 0 ·