Forums

Official Django Tutorial on PythonAnywhere

Instruction include placing this code in wsgi.py:

path = os.path.expanduser('~/mysite')
if path not in sys.path:
    sys.path.insert(0, path)

For my app, path is not in sys.path.

Code executes correctly but result of sys.path.insert(0,path) is unexpected: None. Thus index is not loading (eg. never get to app\urls.py).

What is correct syntax?

That's the correct syntax; could you explain a little more about what you mean when you say that the result of the insert is None? Are you seeing that in an error message somewhere?

When I execute via bash: python3 /var/www/<myusername>_pythonanywhere_com_wsgi.py I obtain: None

path = os.path.expanduser('~/mysite')

if path not in sys.path: print(sys.path.insert(0, path)) sys.path.insert(0, path)

Problem may be more involved. Am trouble-shooting this problem to solve: Page not found (404)

Using the URLconf defined in mysite.urls, Django tried these URL patterns, in this order: app2/ admin/ The empty path didn't match any of these.

Can you offer assistance in trouble-shooting Page not found?

Appears this code correctly loaded /home/BigRed12/mysite into sys.path:

In [14]: print(path)
/home/BigRed12/mysite In [15]: if path not in sys.path: ...: sys.path.insert(0, path) ...:
In [16]: for d in sys.path: ...: print(d) ...:
/home/BigRed12/mysite

Never mind. 6hrs later...got it.

Going to the wrong URL.

URL is not /, it is /app2.

Once redirected to /app2 it works.

OK, glad you worked it out!