Jump to content

Recommended Posts

Posted

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.

 

Posted

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).

 

Posted

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?

Posted (edited)

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
Posted

Thanks @leogama.  I copied everything you did and it worked for me.  Now I have a base to try my app from.

 

RE: the wiki, I'm not sure what the best way to fix it is (one hello dir or two?)

Posted

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.

  • 2 months later...
Posted (edited)

@leogama you are a legend! I'd been trying to get my darn website working for ages before finding your post.

Edited by samuelss

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...