0

As a beginner in Python i must understand this code:

from settings import PROJECT_ROOT

--> I am trying in the Python Shell to type this but Python gives me a Traceback even though i have such a module

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
        'NAME': '',                      # Or path to database file if using sqlite3.
        'USER': '',                      # Not used with sqlite3.
        'PASSWORD': '',                  # Not used with sqlite3.
        'HOST': '',                      # Set to empty string for localhost. Not used with sqlite3.
        'PORT': '',                      # Set to empty string for default. Not used with sqlite3.
    }
}

--> I want to use sqlite the db that is built into Python but i really can't understand what i must do

Pardon me for the basicness of the question but i feel overwhelmed by the task i have in Python these days.

For reasons of completness this is all the code in the module which is called settings.py:

from settings import PROJECT_ROOT

DEBUG = True
TEMPLATE_DEBUG = DEBUG


DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
        'NAME': '',                      # Or path to database file if using sqlite3.
        'USER': '',                      # Not used with sqlite3.
        'PASSWORD': '',                  # Not used with sqlite3.
        'HOST': '',                      # Set to empty string for localhost. Not used with sqlite3.
        'PORT': '',                      # Set to empty string for default. Not used with sqlite3.
    }
}


# Make this unique, and don't share it with anybody.
SECRET_KEY = ''

# Python dotted path to the WSGI application used by Django's runserver; added in v1.4
WSGI_APPLICATION = 'wsgi.application'

############### PYSEC specific variables

# assumes this directory exists
DATA_DIR = "%s/pysec/data/" % PROJECT_ROOT

UPDATE

I dont want to stress your already overstressed patience but why does it keep telling me the SECRET_KEY value is empty? I put

# Make this unique, and don't share it with anybody.
SECRET_KEY = 'sdfgtardyure34654356435'

and it gives me ths in text

raise ImproperlyConfigured("The SECRET_KEY setting must not be empty.")

Here it is in a pic in the cmd

enter image description here

ExoticBirdsMerchant
  • 1,466
  • 8
  • 28
  • 53

1 Answers1

1

Try using python manage.py shell to open the python shell.

Usually the settings.py file reside inside the project root directory, so in order to import the PROJECT_ROOT variable, you can use from project_name.settings import PROJECT_ROOT

[EDIT]

To use the sqlite engine, change the DATABASES dictionary to:

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

2[EDIT]

There's no stress. Like a tip, see this Adding Python Path on Windows 7 question to add the python files to the win path variable, this help you to avoid to put your projects inside c:PythonXX, and use another directory instead.

I've take a look at the linked github project, and it seems to explain inside the README file that you must add a SECRET_KEY and a DATA_DIR variables.

Here's a workaround I've done to get work that project:

$ git clone https://github.com/lukerosiak/pysec.git
$ cd pysec
$ ls # the dir command when on Windows
README.md
TODO.md
local_settings-example.py
manage.py*
pysec/
requirements.txt
settings.py*
$ cp local_settings-example.py local_settings.py

Edit the local_settings.py file and modify the SECRET_KEY and DATA_DIR variables:

SECRET_KEY = '@r65u-33&#2v3vu-e^h-%u4kg=g9y5z'
DATA_DIR = '/home/slacker/pysec/project_database' # or something like: C:\\users\tosh\pysec\

project_database Run:

$ python manage.py syncdb

I hope it can help!

Community
  • 1
  • 1
slackmart
  • 4,754
  • 3
  • 25
  • 39
  • I typed on the command prompt `python manage.py shell' and it didn't work. I also tried to type the same thing in the GUI but it immediately gave me invalid syntax. The `settings.py` is in the Python27 file... I also tried to type `from project_name.settings import PROJECT_ROOT` in the GUI and the CMD but nothing. snif – ExoticBirdsMerchant Apr 13 '14 at 20:08
  • 1
    Before exec the `python manage.py shell`, you must change to the project root directory (since the `manage.py` lives there). For instance, my project reside inside `/home/user_my/project_name`, so go to there `cd /home/user_my/project_name` and then exec the `python manage.py shell` – slackmart Apr 13 '14 at 20:12
  • it says the `SECRET_KEY` must not be empty although i filled with 10 characters the `SECRET_KEY` closed the `cmd` and reopened it and went to the roor file. – ExoticBirdsMerchant Apr 13 '14 at 20:17
  • this is BAZINGAAAAAAAAAAA – ExoticBirdsMerchant Apr 13 '14 at 20:17
  • Thanks for the input @sgmart!!! However i have a slight problem whenever i try to type `$ git clone https://github.com/lukerosiak/pysec.git` in the cmd it says git is not recognised as an internal or external command – ExoticBirdsMerchant Apr 13 '14 at 23:02
  • Ok, That means you you haven't `git` installed. So, skip that step and use this one link: https://github.com/lukerosiak/pysec/archive/master.zip to download the package, then unzip the compressed file and edit the `local-settings.py` as showed before. – slackmart Apr 14 '14 at 03:02