Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8676415
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T20:11:24+00:00 2026-06-12T20:11:24+00:00

There are my post on this query but most of them are for linux.

  • 0

There are my post on this query but most of them are for linux. None of them exlicitly for windows

in my application i’m setting up the database (sqlite3 , default in Django). after editing setting.py file of my application (mysite)

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
        'NAME': 'D:/Django_Code/sqlite.db',                      # 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.
    }
}

after finding that i have to set DJANGO_SETTINGS_MODULE environment so that Django can know about the database setting. So i set it up like

DJANGO_SETTINGS_MODULE = "D:\Django_Code\mysite\mysite\settings.py"

To cross check the database setup when i issue

>>> from django.db import connection
>>> cursor = connection.cursor()

it says DJANGO_SETTINGS_MODULE environment variable is Undefined.

Need help to set DJANGO_SETTINGS_MODULE correctly.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T20:11:26+00:00Added an answer on June 12, 2026 at 8:11 pm

    The easiest way to set DJANGO_SETTINGS_MODULE in Windows is using the set command from the command prompt. You should also be able to set it via system properties, but you’d need to close and reopen the command prompt for the changes to take effect.

    You can query the current value of DJANGO_SETTINGS_MODULE using the set command as well:

    C:\temp\testproject> set DJANGO_SETTINGS_MODULE
    

    In addition, you need to set it to the python module name, not the filename (setting it to the filename will give you an error similar to “Could not import settings ‘C:\temp\testproject\settings.py’ (Is it on sys.path?): Import by filename is not supported.“)

    For example,

    C:\temp\testproject> set DJANGO_SETTINGS_MODULE=testproject.settings
    

    Then you can run python and the module can be imported.

    >>> import sys
    >>> sys.path += ['C:\\temp']
    >>> from django.db import connection
    >>> connection.cursor()
    <django.db.backends.util.CursorDebugWrapper object at 0x02C7F0B0>
    

    Note that we’ve also explicitly added the directory containing the django project (testproject in this case) to sys.path, which is effectively a list of directories where Python looks for modules. This is necessary because Python imports the settings file as a python module, not a file (as mentioned earlier).

    If you want an interactive shell to play with Django objects, you can use the shell management command. In your Django project directory, run the following command:

    manage.py shell
    

    Since you’re on windows, you may have to do

    python manage.py shell
    

    instead, since I’ve personally had issues with python scripts not receiving command line arguments otherwise.

    C:\temp\testproject> python manage.py shell
    
    In [1]: from django.db import connection
    
    In [2]: connection.cursor()
    Out[2]: <django.db.backends.util.CursorDebugWrapper at 0x33a0bd0>
    

    (Note that I have IPython installed and Django is being clever and using that; if you don’t have IPython installed, your shell will look slightly different.)

    If you want to run a script with Django, the easiest way is to write a custom management command, which you can then run with an argument to manage.py.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

There is a post on this topic already, but it does not have an
I know there is this post , but I still want to know more
I am writing a class for database queries with SQLite3 in my application. Most
Referring back to this SO post If there is a Grouping category Category which,
Paul Silver had this post 7 years ago to check various browsers. Has there
There are several scripting environments available for .NET applications (e.g. this post ). My
Before I get anywhere with this post, let me make this clear, there is
There is a post here that talks about this as being a bad idea
This question is related with one of my earlier questions.. Previous Post In there
This question is related to a previous post . Is there something comparable to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.