AWS Lightsail deploing - To serve your application through the Apache web server, login is not allowed

Keywords: Django - AWS - Technical issue - Other
bnsupport ID: 75214288-b8ea-7a08-982a-eb3ad07a853b
Description:
Hi,
I’m new to Bitnami.
I have a problem with my web application.

if I use the standalone server, my application works fine.

I have the need to serve my application through the Apache web server with the mod_wsgi module.

I followed the procedure I found on the link: https://docs.bitnami.com/aws/infrastructure/django/get-started/deploy-django-project/

I can use the application in all those parts where it is not required to login.

I can’t log on the ‘Django administration’ (
For example http:///admin/login/) or in all those parts that require login (@login_required)

I get the answer: Server Error (500).

In the log file I find:

2.42.220.180 - - [18/Jun/2021:15:23:25 +0000] "GET /admin/login/ HTTP/1.1" 200 868
2.42.220.180 - - [18/Jun/2021:15:23:38 +0000] "POST /admin/login/ HTTP/1.1" 500 145

I have no more ideas to solve the problem.

Any help would be much appreciated.

Hi @piacenza.federico,

I understand that you launched the python server in the same instance and accessed the web application using the browser, right? Did you open the port in the firewall?

I just found this error in the Apache’s log but it doesn’t seem related with the login_required error message

[Fri Jun 18 13:10:01.727880 2021] [wsgi:error] [pid 3314] [remote 2.42.220.180:24618] sys.version_info(major=3, minor=8, micro=7, releaselevel='final', serial=0)
Exception ignored in: <function BaseEventLoop.__del__ at 0x7f20a9e0bca0>
Traceback (most recent call last):
  File "/opt/bitnami/python/lib/python3.8/asyncio/base_events.py", line 654, in __del__
NameError: name 'ResourceWarning' is not defined
Exception ignored in: <function BaseEventLoop.__del__ at 0x7f20a9e0bca0>
Traceback (most recent call last):
  File "/opt/bitnami/python/lib/python3.8/asyncio/base_events.py", line 654, in __del__
NameError: name 'ResourceWarning' is not defined
Exception ignored in: <function Local.__del__ at 0x7f20a9d7b550>
Traceback (most recent call last):
  File "/opt/bitnami/python/lib/python3.8/site-packages/asgiref/local.py", line 96, in __del__
NameError: name 'TypeError' is not defined
Exception ignored in: <function Local.__del__ at 0x7f20a9d7b550>
Traceback (most recent call last):
  File "/opt/bitnami/python/lib/python3.8/site-packages/asgiref/local.py", line 96, in __del__
NameError: name 'TypeError' is not defined
Exception ignored in: <function Local.__del__ at 0x7f20a9d7b550>
Traceback (most recent call last):
  File "/opt/bitnami/python/lib/python3.8/site-packages/asgiref/local.py", line 96, in __del__
NameError: name 'TypeError' is not defined
Exception ignored in: <function Local.__del__ at 0x7f20a9d7b550>
Traceback (most recent call last):
  File "/opt/bitnami/python/lib/python3.8/site-packages/asgiref/local.py", line 96, in __del__
NameError: name 'TypeError' is not defined
Exception ignored in: <function Local.__del__ at 0x7f20a9d7b550>
Traceback (most recent call last):
  File "/opt/bitnami/python/lib/python3.8/site-packages/asgiref/local.py", line 96, in __del__
NameError: name 'TypeError' is not defined
Exception ignored in: <function Local.__del__ at 0x7f20a9d7b550>
Traceback (most recent call last):
  File "/opt/bitnami/python/lib/python3.8/site-packages/asgiref/local.py", line 96, in __del__
NameError: name 'TypeError' is not defined

Does this happen with all the Django apps you deployed in your instance? Can you try to deploy a sample application and see if the problem occurs in that new deployment?

Hi, Jota

I understand that you launched the python server in the same instance and accessed the web application using the browser, right? Did you open the port in the firewall?

yes, I access the web application using the browser.
yes, the ports are correctly open because I can access all views that do not require login.

I followed your advice and deploys the sample app Tool_Example.
this app is very simple, and has only one view function (index()) in /opt/bitnami/projects/Tool_Example/appExample/views.py

from django.shortcuts import render
from django.contrib.auth.decorators import login_required
from django.http import HttpResponse

def index(request):
return HttpResponse(“Example view”)

In developement mode (python3 manage.py runserver 0.0.0.0:8000) the web app works correctly.

In Production mode the following occurs:

in the access logs I find:

  • -[21/Jun/2021:13:02:17 +0000] “POST /admin/login/?next=/admin/ HTTP/1.1” 500 145
  • - [21/Jun/2021:13:03:09 +0000] “-” 408

Maybe it’s a problem related to POST requests?

I went to the settings.py file and I set DEBUG = True.
I tried to login with the following result:

It might be useful to know that there appears to be a write permissions problem on the db.

Exception Value:attempt to write a readonly database

however I cannot set the correct permissions.

Hi @piacenza.federico,

Where can we find this sample app?

Did you configure the database credentials for the app?

https://docs.bitnami.com/aws/infrastructure/django/get-started/start-django-project/

It seems you are using sqlite3 as database, does the daemon user/group have write permissions inside your projects/Tool_Example folder? You can try to set the permissions this way

sudo chown -R bitnami:daemon /opt/bitnami/projects/Tool_Example
sudo chmod -R g+w opt/bitnami/projects/Tool_Example

Can you access the app now?

yes, i am using sqlite3.

I tried to set the permissions as you told me, and now it works correctly.

I thank you infinitely for your help

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.