Jump to content

[Solved] Django 500 error


logdog

Recommended Posts

Having problem getting Django app to work.

 

Did all the steps here http://www.heliohost.org/classic/features/languages/python

 

Is there anything that needs to be done to turn on Django/Python for the account?

Or, is there anyway to get some error output for troubleshooting?

 

My project name is h1

Creating a project you get an h1 dir and another one named h1 dir under it.

So location for dispatcher is

public_html/h1/h1/dispatcher.wsgi

 

have also created

public_html/h1/media/test.html

 

I tested the media exemption and it works fine, so I think there needs to be some extra h1 dirs in the .htaccess

similar to the inforiesgoserver/inforiesgoserver/... in this example:  https://www.helionet.org/index/topic/29558-django-project-not-working/

 

It appears that the filter regex is relative to the location of the .htaccess (../public_html/h1/)  and the target is relative to the account root (../public_html/)

 

Something like this:

RewriteEngine On
RewriteBase /
RewriteRule ^(media/.*)$ - [L]
RewriteRule ^(admin_media/.*)$ - [L]
RewriteRule ^(h1/dispatch\.wsgi/.*)$ - [L]
RewriteRule ^(.*)$ h1/h1/dispatch.wsgi/$1 [QSA,PT,L]

 

But, that does not work either.

 

 

Please advise.

 

Link to comment
Share on other sites

No, no. That's some old stuff there. Try here.

I had some troubles setting up Django yesterday, even after following this tutorial step-by-step. It turned out that there's an error in one of the code snippets.

 

In the example dispatch.wsgi file, where it shows:

# edit your username below
sys.path.append("/home/username_on_heliohost/public_html")

should be:

# edit your username below
sys.path.append("/home/username_on_heliohost/public_html/hello")

which is the Django project root directory. Otherwise, you'll get a 500 Internal Server Error response because Python can't find the application module (that is at "/home/username_on_heliohost/public_html/hello/hello").

 

Would you change the Django application to the website's root in the future, you should update this line accordingly and also move the .htaccess file to the root (without changes).

 

Link to comment
Share on other sites

Thanks for the help.

The content in the wiki has a contradiction

 

On local host, you have  two hello dirs

../hello/manage.py

../hello/hello/dispatch.wsgi

 

The tree output (right after the allowed_hosts section of wiki) shows that the project content was uploaded directly to public_html/  So, the top level hello is not on heliohost

you have:

../public_html/manage.py

../public_html/hello/dispatch.wsgi

 

The contradiction comes in the .htaccess file in the wiki.  It shows two hello levels whereas there is only one on heliohost per the tree output.

RewriteRule ^(.*)$ hello/hello/dispatch.wsgi/$1 [QSA,PT,L]

 

@leogama, sounds like you got it working by not putting project content in your public_html.  In other words, you kept the top level "hello"

Can you share your tree view, .htaccess and dispatch.wsgi?

Link to comment
Share on other sites

You're right, @logdog. The tutorial is contradictory in this regard.

 

This minimal setup worked for me (other files are not required):

$ tree public_html
public_html
├── django_test
│   ├── __init__.py
│   ├── dispatch.wsgi
│   ├── settings.py
│   ├── urls.py
│   ├── views.py
│   └── wsgi.py -> dispatch.wsgi
└── .htaccess

Files' content (__init__.py is empty):

 

.htaccess

RewriteEngine On
RewriteBase /
RewriteRule ^(media/.*)$ - [L]
RewriteRule ^(django_test/dispatch\.wsgi/.*)$ - [L]
RewriteRule ^(.*)$ django_test/dispatch.wsgi/$1 [QSA,PT,L]

dispatch.wsgi

import os, sys

# Change "username_on_heliohost" to the actual username
sys.path.append('/home/username_on_heliohost/public_html')

# More portable version
#from pathlib import Path
#sys.path.append(str(Path(__file__).parent.parent))

from django.core.wsgi import get_wsgi_application

os.environ['DJANGO_SETTINGS_MODULE'] = 'django_test.settings'

application = get_wsgi_application()

settings.py

SECRET_KEY = 'CHANGE THIS!'
ALLOWED_HOSTS = ['*']
ROOT_URLCONF = 'django_test.urls'

urls.py

from django.urls import path

from . import views

urlpatterns = [
    path('', views.index),
]

views.py

from django.http import HttpResponse

def index(request):
    return HttpResponse("Hello, World!")

Hope it helps :rolleyes:

Edited by leogama
  • Like 1
Link to comment
Share on other sites

The reason the wiki has two hello directories is because that is the way the command

django-admin startproject hello

creates the code, and then you can upload it to the server by symlinking dispatch.wsgi and adding the .htaccess. Obviously it will work with other directory configurations.

Link to comment
Share on other sites

  • 2 months later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...