Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NameError: name 'BASE_DIR' is not defined #1649

Open
phil-saam opened this issue Mar 10, 2020 · 10 comments
Open

NameError: name 'BASE_DIR' is not defined #1649

phil-saam opened this issue Mar 10, 2020 · 10 comments

Comments

@phil-saam
Copy link

phil-saam commented Mar 10, 2020

Issue description

Can't load page on pythonanywhere always get the same error message

2020-03-09 17:58:50,262: Error running WSGI application
2020-03-09 17:58:50,277: NameError: name 'BASE_DIR' is not defined
2020-03-09 17:58:50,277:   File "/var/www/hpylori_pythonanywhere_com_wsgi.py", line 15, in <module>
2020-03-09 17:58:50,277:     application = get_wsgi_application()
2020-03-09 17:58:50,277: 
2020-03-09 17:58:50,278:   File "/home/HPylori/hpylori.pythonanywhere.com/myenv/Lib/site-packages/django/core/wsgi.py", line 12, in get_wsgi_application
2020-03-09 17:58:50,278:     django.setup(set_prefix=False)
2020-03-09 17:58:50,278: 
2020-03-09 17:58:50,278:   File "/home/HPylori/hpylori.pythonanywhere.com/myenv/Lib/site-packages/django/__init__.py", line 19, in setup
2020-03-09 17:58:50,278:     configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
2020-03-09 17:58:50,279: 
2020-03-09 17:58:50,279:   File "/home/HPylori/hpylori.pythonanywhere.com/myenv/Lib/site-packages/django/conf/__init__.py", line 76, in __getattr__
2020-03-09 17:58:50,279:     self._setup(name)
2020-03-09 17:58:50,279: 
2020-03-09 17:58:50,279:   File "/home/HPylori/hpylori.pythonanywhere.com/myenv/Lib/site-packages/django/conf/__init__.py", line 63, in _setup
2020-03-09 17:58:50,279:     self._wrapped = Settings(settings_module)
2020-03-09 17:58:50,279: 
2020-03-09 17:58:50,279:   File "/home/HPylori/hpylori.pythonanywhere.com/myenv/Lib/site-packages/django/conf/__init__.py", line 142, in __init__
2020-03-09 17:58:50,280:     mod = importlib.import_module(self.SETTINGS_MODULE)
2020-03-09 17:58:50,280: 
2020-03-09 17:58:50,280:   File "/home/HPylori/hpylori.pythonanywhere.com/myenv/Lib/site-packages/isort/__init__.py", line 25, in <module>
2020-03-09 17:58:50,280:     from . import settings  # noqa: F401
2020-03-09 17:58:50,280: 
2020-03-09 17:58:50,280:   File "/home/HPylori/hpylori.pythonanywhere.com/myenv/Lib/site-packages/isort/settings.py", line 359, in <module>
2020-03-09 17:58:50,281:     STATIC_ROOT = os.path.join(BASE_DIR, 'static')

Language

Django

Operating system

Windows

hpylori.pythonanywhere.com.error.log

"""
Django settings for mysite project.

Generated by 'django-admin startproject' using Django 3.0.3.

For more information on this file, see
https://docs.djangoproject.com/en/3.0/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/3.0/ref/settings/
"""

import os

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/3.0/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '************'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = ['127.0.0.1', '.pythonanywhere.com']

# Application definition

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'blog.apps.BlogConfig',
]

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

ROOT_URLCONF = 'mysite.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]

WSGI_APPLICATION = 'mysite.wsgi.application'


# Database
# https://docs.djangoproject.com/en/3.0/ref/settings/#databases

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
    }
}


# Password validation
# https://docs.djangoproject.com/en/3.0/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
    {
        'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
    },
]


# Internationalization
# https://docs.djangoproject.com/en/3.0/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'America/Chicago'

USE_I18N = True

USE_L10N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/3.0/howto/static-files/

STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
@ekohl
Copy link
Collaborator

ekohl commented Mar 10, 2020

Which Django version are you using? The BASE_DIR variable in settings.py only came since some version. It might be useful to share your entire settings.py.

@phil-saam
Copy link
Author

Added my settings.py file, I am using version 3.0.3 do you know what would need to be changed with the BASE_DIR settings? Thanks,

@ekohl
Copy link
Collaborator

ekohl commented Mar 11, 2020

That doesn't make sense because it's defined at the top of the file. It feels like the file on pythonanywhere.org might be different than what you have locally. I'd check if there's any difference.

@ghost
Copy link

ghost commented Apr 6, 2020

Has anyone figured this out yet? I am having the same issue.

>>> django.VERSION
(3, 0, 5, 'final', 0)

@das-g
Copy link
Member

das-g commented Apr 6, 2020

The tutorial currently assumes Django 2.2.x and that is also what it tells you to install in the "Django installation" chapter. For other Django versions, the instructions in the tutorial might not work.

Help in updating the instructions for a newer Django version would be appreciated. Though, until the tutorial is available for a newer Django version, please use Django 2.2.x for following the tutorial.

According to the Django documentation, Django 2.2 has extended support until April 2022, so although there are higher versions available, it's not outdated, yet.

I therefore propose to close this issue.

@Nanouchkaya
Copy link

Hi!
Did anyone find a solution? I get the same error message with Django 2.2.16
Thanks!

@ekohl
Copy link
Collaborator

ekohl commented Oct 21, 2020

Please verify BASE_DIR is in your settings.py. It should be by default. It looks something like this:

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

Also verify that the settings.py file on PythonAnywhere matches. The command git diff may help to show the differences.

@OzlemAkgunoglu
Copy link

i have the same problem ...

@hotfix
Copy link

hotfix commented Apr 7, 2022

To solve it, the WSGI file should be updated
https://help.pythonanywhere.com/pages/DeployExistingDjangoProject/

@nikhiljohn10
Copy link
Contributor

Is this issue still valid after upgrading the Django version to 3.x in the tutorial?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants