Django Admin Page gives 403 Forbidden error

I have a django website hosted on AWS using Copilot. The admin page keeps giving a 403 forbidden error, while rest of the views work fine.

Here is my settings.py config -

I saw mutliple issues on this topic but none of them seem to have a clear solution how to fix this.

Side note. Please do not post images of code here. Copy/paste the code into the body of your post, between lines of three backtick - ` characters. This means you’ll have a line of ```, then your code, then another line of ```.

Do you have more details about the specific 403 error being thrown? What is the complete response being returned by the server? What about the server logs?
There are many things that can throw a 403. Knowing which specific 403 is being issued is important to know what the solution would be…

You may want to log these environment variables to verify that they’re what you’re expecting them to be.

Hey Ken,

Thanks for the reply. I figured out the issue was being raised by the AWS loadbalancer where it was directly blocking requests made to the django admin portal. This might be useful to document but I found a way around to fix it.

Appreciate your help. Thanks!

Hey vshah,

I am encountering the same problem - how did you manage to overcome this?

Hey hetryn,

So my application was hosted on aws with a loadbalancer in the front. It had a rule group that disallowed any direct attempts to hit the admin url because of which I kept getting the 403 forbidden page.

I was able to resolve it by updating the rule group to add some exception sets where access to the admin pages from a fixed set of ip/region based addresses are allowed. Hope this helps!

Hi hetryn,

Did you manage to find a solution? I am also facing same problem.