Forums

Where is the error?

Работаю на django, не получается войти ни в панель администратора, ни на сайт.

katyalima.pythonanywhere.com.error.log

2018-07-03 16:40:40,668: SyntaxError: invalid syntax
2018-07-03 16:40:40,668: ***************************************************
2018-07-03 16:40:40,668: If you're seeing an import error and don't know why,
2018-07-03 16:40:40,668: we have a dedicated help page to help you debug: 
2018-07-03 16:40:40,668: https://help.pythonanywhere.com/pages/DebuggingImportError/
2018-07-03 16:40:40,669: ***************************************************
2018-07-03 16:42:38,944: Error running WSGI application
2018-07-03 16:42:38,950:   File "/var/www/katyalima_pythonanywhere_com_wsgi.py", line 87
2018-07-03 16:42:38,951: 
2018-07-03 16:42:38,951:     then:
2018-07-03 16:42:38,951: 
2018-07-03 16:42:38,951:         ^
2018-07-03 16:42:38,952: 
2018-07-03 16:42:38,952: SyntaxError: invalid syntax
2018-07-03 16:42:38,952: ***************************************************
2018-07-03 16:42:38,952: If you're seeing an import error and don't know why,
2018-07-03 16:42:38,952: we have a dedicated help page to help you debug: 
2018-07-03 16:42:38,953: https://help.pythonanywhere.com/pages/DebuggingImportError/
2018-07-03 16:42:38,953: ***************************************************

/var/www/katyalima_pythonanywhere_com_wsgi.py

This file contains the WSGI configuration required to serve up your
# web application at http://KatyaLima.pythonanywhere.com/
# It works by setting the variable 'application' to a WSGI handler of some
# description.
#

# +++++++++++ GENERAL DEBUGGING TIPS +++++++++++
# getting imports and sys.path right can be fiddly!
# We've tried to collect some general tips here:
# https://www.pythonanywhere.com/wiki/DebuggingImportError


# +++++++++++ HELLO WORLD +++++++++++
# A little pure-wsgi hello world we've cooked up, just
# to prove everything works.  You should delete this
# code to get your own working.


HELLO_WORLD = """<html>
<head>
    <title>Python Anywhere hosted web application</title>
</head>
<body>
<h1>Hello, World!</h1>
<p>
    This is the default welcome page for a
    <a href="https://www.pythonanywhere.com/">PythonAnywhere</a>
    hosted web application.
</p>
<p>
    Find out more about how to configure your own web application
    by visiting the <a href="https://www.pythonanywhere.com/web_app_setup/">web app setup</a> page
</p>
</body>
</html>"""


def application(environ, start_response):
    if environ.get('PATH_INFO') == '/':
        status = '200 OK'
        content = HELLO_WORLD
    else:
        status = '404 NOT FOUND'
        content = 'Page not found.'
    response_headers = [('Content-Type', 'text/html'), ('Content-Length', str(len(content)))]
    start_response(status, response_headers)
    yield content.encode('utf8')


# Below are templates for Django and Flask.  You should update the file
# appropriately for the web framework you're using, and then
# click the 'Reload /yourdomain.com/' button on the 'Web' tab to make your site
# live.

# +++++++++++ VIRTUALENV +++++++++++
# If you want to use a virtualenv, set its path on the web app setup tab.
# Then come back here and import your application object as per the
# instructions below


# +++++++++++ CUSTOM WSGI +++++++++++
# If you have a WSGI file that you want to serve using PythonAnywhere, perhaps
# in your home directory under version control, then use something like this:
#
#import sys
#
#path = '/home/KatyaLima/path/to/my/app
#if path not in sys.path:
#    sys.path.append(path)
#
#from my_wsgi_file import application  # noqa


# +++++++++++ DJANGO +++++++++++
# To use your own django app use code like this:
import os
import sys

##assuming your django settings file is at '/home/KatyaLima/mysite/mysite/settings.py'
##and your manage.py is is at '/home/KatyaLima/mysite/manage.py'
path = '/home/KatyaLima/mysite'
if path not in sys.path:
    sys.path.append(path)

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

then:

  from django.core.wsgi import get_wsgi_application
  application = get_wsgi_application()



# +++++++++++ FLASK +++++++++++
# Flask works like any other WSGI-compatible framework, we just need
# to import the application.  Often Flask apps are called "app" so we
# may need to rename it during the import:
#
#
#import sys
#
## The "/home/KatyaLima" below specifies your home
## directory -- the rest should be the directory you uploaded your Flask
## code to underneath the home directory.  So if you just ran
## "git clone git@github.com/myusername/myproject.git"
## ...or uploaded files to the directory "myproject", then you should
## specify "/home/KatyaLima/myproject"
#path = '/home/KatyaLima/path/to/flask_app_directory'
#if path not in sys.path:
#    sys.path.append(path)
#
#from main_flask_app_file import app as application  # noqa
#
# NB -- many Flask guides suggest you use a file called run.py; that's
# not necessary on PythonAnywhere.  And you should make sure your code
# does *not* invoke the flask development server with app.run(), as it
# will prevent your wsgi file from working.

[edit by admin: formatting]

The problem is in this bit of code:

path = '/home/KatyaLima/mysite'
if path not in sys.path:
    sys.path.append(path)

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

then:

  from django.core.wsgi import get_wsgi_application
  application = get_wsgi_application()

It should just be this:

path = '/home/KatyaLima/mysite'
if path not in sys.path:
    sys.path.append(path)

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

from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()

Thanks. I've already dealt with it. :-)