logdog Posted March 1, 2020 Posted March 1, 2020 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 h1Creating a project you get an h1 dir and another one named h1 dir under it.So location for dispatcher ispublic_html/h1/h1/dispatcher.wsgi have also createdpublic_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 .htaccesssimilar 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 OnRewriteBase /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.
leogama Posted March 1, 2020 Posted March 1, 2020 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).
logdog Posted March 1, 2020 Author Posted March 1, 2020 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 heliohostyou 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?
leogama Posted March 1, 2020 Posted March 1, 2020 (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 Edited March 1, 2020 by leogama 1
Krydos Posted March 2, 2020 Posted March 2, 2020 If there's a problem with the wiki any HelioHost user can edit it. You can get your wiki account set up at https://www.helionet.org/index/topic/34285-wiki-access-requests/
logdog Posted March 2, 2020 Author Posted March 2, 2020 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?)
Krydos Posted March 3, 2020 Posted March 3, 2020 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.
samuelss Posted May 19, 2020 Posted May 19, 2020 (edited) @leogama you are a legend! I'd been trying to get my darn website working for ages before finding your post. Edited May 19, 2020 by samuelss
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now