Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The SECRET_KEY setting must not be empty - django+pycharm

For sure I searched a few posts but none of them helped though. Even the closest one didn't help too.

I am currently using pyCharm installed django using virtual environment. As I have tried lots of ways but no luck using pycharm to run the project BUT if I do it in the terminal by using python manage.py runserver the server runs properly though. Somehow in pyCharm after all the setup, it just wouldn't let me run. Where am I setting it wrong in pycharm?

Anyways, I am getting this error

raise ImproperlyConfigured("The SECRET_KEY setting must not be empty.") django.core.exceptions.ImproperlyConfigured: The SECRET_KEY setting must not be empty.

my manage.py as some posts were talking about this but I see it's setting up properly though

#!/usr/bin/env python
import os
import sys

if __name__ == "__main__":
    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "CodingEntrepreneurs.settings")
    try:
        from django.core.management import execute_from_command_line
    except ImportError:
        # The above import may fail for some other reason. Ensure that the
        # issue is really that Django is missing to avoid masking other
        # exceptions on Python 2.
        try:
            import django
        except ImportError:
            raise ImportError(
                "Couldn't import Django. Are you sure it's installed and "
                "available on your PYTHONPATH environment variable? Did you "
                "forget to activate a virtual environment?"
            )
        raise
    execute_from_command_line(sys.argv)

my settings.py (without saying much, I do have the KEY)

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

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

`

my folder structure

my folder structure

my run-debug config

my run-debug config

my django-framework setting

my django-framework setting

like image 595
Dora Avatar asked Jan 20 '17 00:01

Dora


1 Answers

Since it was a question from 20th of january, I do think it has been resolved already. However, I'd like to share my fix to the same issue.

I ran in into to same issue here. I've been struggling around for a while. Finally it seemed to be an issue with the Environment Variables, as shown in your second screenshot (Run/Debug Configurations)

I've fixed it by updating the Environment Variables path from

DJANGO_SETTINGS_MODULE=portfolio; <..crop..>

to

DJANGO_SETTINGS_MODULE=portfolio.settings; <..crop..>

I had to add settings to the DJANGO_SETTINGS_MODULE path.

like image 198
Nrzonline Avatar answered Sep 27 '22 22:09

Nrzonline