Search Google

Saturday 12 July 2014

how to install django on win 7 and run your first web app

 HOW  TO RUN startproject mysite
    cd mysite
    python syncdb

    (Follow prompts to setup an initial db. remember the user you used here.)

    python runserver


DJANGO can be install by pip or by simply
Django via python If it’s not on your path, you can find it in site-packages/django/bin

You can just run django-admin startproject mysite(Note: not, because if you install django by pip, a executable program named 'django-admin.exe' will be added to 'C:\Python34\Scripts', which is already in your environment variable 'PATH' normally(if not, add it to PATH).

 for runing

1. through type on cmd django-admin startproject mysite

2.pip - startproject mysite

This is a guide for installing Python (a programming language) and Django (a web framework written in Python) on a computer that runs Windows 7. I initially wrote this to help the Windows users on my team (for a project this semester), but I figured it could be immortalized here. Hopefully someone out there on the internet will find this useful.


Download this:
Now, run that installer. It should install Python in C:\Python27. If you
choose a different installation directory, that’s fine, but just remember which directory it was for later steps in this tutorial. Great. Python should be installed. However, if you open a command prompt (start -> search cmd.exe), you will notice that the command python.exe will not run the Python interpreter. That’s annoying — you would have to type out C:\Python27\python.exe every time you wanted to run the Python interpreter.
To fix this, we want to add Python to the system path. This lets cmd.exe know what you’re talking about when you invoke python.exe. To add Python to the system path, open the windows menu and search “environment variable”. You should get an option like “Edit your environment variables”. Choose that option. It will open a window.
Click the button “Environment variables…”. There should be two “lists”. Look at the second pane. Scroll down a bit, and you should see a variable called “Path”. Select and click “edit”. Cool. You should have something like:
%SYSTEMROOT%\System32;%SYSTEMROOT%\blabla; and so on.
Add this to the end of it:
(Substitute the path where you installed python if you didn’t install
it in C:\Python27.
Awesome. Open a new cmd.exe and run the command python.exe. You should get a Python interpreter.


Download this:
Now use 7-zip (or something comparable) to extract it (it doesn’t matter where; your desktop is fine). Now, go into the Django-1.2.3 directory that was just extracted. Figure out the path to this folder (e.g. C:\Windows\Users\Tavish\Desktop\Django-1.2.3).
Now, in cmd.exe (the command prompt), type in cd C:\The\Path\I\Just\Told\You\To\Remember. Then type in python.exe install. Hopefully a whole bunch of text will show up in your terminal. This is a good sign.
Django should be installed now. To test, go to some directory , where you want to make a django project (do this in your command prompt; cd changes directories, dir lists the contents of the current directory, etc.). Then run the following command: startproject newproject
That should create a folder called “newproject”. (You can refer to the official Django documentation for a more in-depth explanation.)
Cool. Do cd newproject to change to that directory. The command dir will show that there is a python script called in there. Run it like this:
python.exe runserver
A message should appear. Use your web browser to open the address, just like your terminal says. If you see a web page at that address saying “It worked!”, then, well, it worked.
Let me know if this works or doesn’t work for you. Suggestions are welcome as well.

Set PATH             c:\python27 and c:\pythoon27\Scripts 
  1. Copy from c:\python27\Scripts to your desired folder
  2. with cmd go to that folder and run python startproject mysite
if not work set full path add the necessary Path to the System PATH as shown below.
Control Panel -> System -> Advanced -> Environment Variables -> PATH.
Add to the PATH:

read here :

run your first web app on windows 7 django

Let's look at what startproject created:
These files are:
  • An empty file that tells Python that this directory should be considered a Python package. (Read more about packages in the official Python docs if you're a Python beginner.)
  • A command-line utility that lets you interact with this Django project in various ways. You can read all the details about in and
  • Settings/configuration for this Django project. Django settings will tell you all about how settings work.
  • The URL declarations for this Django project; a "table of contents" of your Django-powered site. You can read more about URLs in URL dispatcher.

The development server

Let's verify this worked. Change into the mysite directory, if you haven't already, and run the command python runserver. You'll see the following output on the command line:
Validating models...
0 errors found.

Django version 1.0, using settings 'mysite.settings'
Development server is running at
Quit the server with CONTROL-C.

BY pip method

Getting django started on Windows 7 with python 3 and MySQL 5.6

Django is a python web framework library and it works on both python 2 or 3. I will show you how to get python 3 setup in Cygwin environment.

If you're on a Windows OS, the best experience I have when working with Django on Windows is to use Cygwin, a Unix emulator shell that runs on Windows. The pip and django commands would automatically setup in Cygwin's PATH after installed. The default python package on Cygwin is only 2.7 though, so you have to search for "python3" package to get the latest python version. And you can have both versions installed without problem, but the executable are named "python" and "python3" respectively.

1. Install Cygwin python3 package. Verify "python3 -V" is working.
2. Install "pip" by downloading this "" file from and then run "python3". Verify "pip3 --version" is working.
(NOTE: If you are running Windows 7, you might run into this issue: where pip exit without a warning. In this case the workaround is install Cygwin "binutils" and "libuuid-devel" packages, and that fixed the problem for me.)
3. Install "django" by running "pip3 install django"
4. Finally install the MySQL driver with "pip3 install mysql-connector-python --allow-external mysql-connector-python" command.

Now to get a django project started, try these: startproject myapp
The "" script should automatically in your PATH. and this create a new project with initial settings. To switch default database from SQLite3 to MySQL, change the "myapp/" with the following:

    'default': {
        'NAME': 'mydb',
        'ENGINE': 'mysql.connector.django',
        'USER': 'root',
        'PASSWORD': 'secret',

Now I assume you have MySQL 5.6+ installed on your Windows already. Change the root password to match yours or using different DB user. You can now have django app setup the initial database schema tables for this specif myapp with this commad:
cd myapp
python3 syncdb

Follow the prompt and setup your admin user. Now you can start django web app:

python3 runserver 

Open browser to http://localhost:8000/admin. Now try to login 

No comments:

Post a Comment