Debug School

rakesh kumar
rakesh kumar

Posted on

How to run djaango appliaction

How to check where python installation to setup environment variable

Running a Django application on Windows involves a few steps. Assuming you've already set up your Django project, here's a step-by-step guide:

Step 1: Open a Command Prompt
Open a command prompt on your Windows machine. You can do this by searching for "Command Prompt" in the Start menu or using the "Run" dialog (Win + R) and typing cmd.

Step 2: Navigate to Your Project Directory
Use the cd command to navigate to the directory where your Django project is located. For example:

cd path\to\your\django\project
Enter fullscreen mode Exit fullscreen mode

Replace path\to\your\django\project with the actual path to your Django project.

Step 3: Activate Virtual Environment (Optional but Recommended)
If you're using a virtual environment (which is recommended), activate it. If you don't have a virtual environment set up, you can skip this step.

# Assuming your virtual environment is named "venv"
venv\Scripts\activate
Enter fullscreen mode Exit fullscreen mode

Step 4: Run Migrations
Run the following command to apply migrations:

python manage.py migrate
Enter fullscreen mode Exit fullscreen mode

This command will create the necessary database tables based on your Django models.

Step 5: Create Superuser (Optional)
If your project involves authentication, create a superuser account to access the Django Admin interface:

python manage.py createsuperuser
Enter fullscreen mode Exit fullscreen mode

Follow the prompts to set up your superuser account.

Step 6: Run Development Server
Start the Django development server using the following command:

python manage.py runserver
Enter fullscreen mode Exit fullscreen mode

Step 7: Access Your Django Application
Open your web browser and go to http://127.0.0.1:8000/ or http://localhost:8000/. You should see your Django application's default welcome page.

If you created a superuser, you can also access the Django Admin interface at http://127.0.0.1:8000/admin/ and log in with the superuser credentials.

To check where Python is installed on your system and set up the environment variable, follow these steps:

Check Python Installation Path:
Open a Command Prompt:

Open a command prompt on your Windows system.
Check Python Installation:

Type the following command and press Enter:

where python
Enter fullscreen mode Exit fullscreen mode

or

where python3
Enter fullscreen mode Exit fullscreen mode

This command will display the path to the Python executable. For example:

C:\Users\YourUsername\AppData\Local\Programs\Python\Python3x\python.exe
Enter fullscreen mode Exit fullscreen mode

Make sure to replace YourUsername with your actual username and Python3x with the specific Python version you have installed.

Set Up Environment Variable

If Python is not in the system PATH, you can add it manually:

Open System Properties:

Right-click on the Computer icon or This PC on your desktop or in the File Explorer.
Select "Properties."
Click on "Advanced system settings":

Go to the "Advanced" tab and click on the "Environment Variables" button.
Edit PATH Variable:

In the "System variables" section, find and select the "Path" variable, then click "Edit."
Add Python to PATH:

Click "New" and add the path to the directory where Python is installed. The default path is usually something like C:\Users\YourUsername\AppData\Local\Programs\Python\Python3x or C:\Program Files\Python3x.

Make sure to replace YourUsername with your actual username and Python3x with the specific Python version you installed.

Save Changes:

Click "OK" to close the windows and save the changes.
After adding Python to the system PATH, open a new command prompt and run python --version or python3 --version to verify that Python is now recognized and accessible from the command line. You should see the Python version information if everything is set up correctly.

Top comments (0)