setting up a new project in django
Here in this post, I am going to write how to start writing a web application using django. And before you start, I believe you have already downloaded and installed django. If not then please do refer http://usepython.blogspot.com/2012/12/getting-started-with-django.html. So we are ready to go?
Now open terminal and lets create a new django project:
Since we have created a new project, change directory using the command:
You're seeing this message because you have DEBUG = True in your Django settings file and you haven't configured any URLs. Get to work!
Before we can start writing our web app, we have to make some configurations to our project and lets do that quick. Open up testProject/settings.py file in your favourite text editor, [ mine is geany ]. Change the line:
And its time to run another command
Now open terminal and lets create a new django project:
$ django-admin.py startproject testProjectThis should create a django web project. That is you will see a directory created in the current working directory of the terminal. The directory will have a structure as follows:
testProject:
- manage.py
- testProject
- __init__.py
- settings.py
- urls.py
- wsgi.py
Since we have created a new project, change directory using the command:
$cd testProjectand run the project using the command:
$ python manage.py runserverIn the command line, you should see something like:
Validating models...This means our project has been successfully created and we can open the url
0 errors found
Django version 1.4.1, using settings 'project.settings'
Development server is running at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
http://127.0.0.1:8000/or
http://localhost:8000/And we should see something like:
It worked!
Congratulations on your first Django-powered page.
Of course, you haven't actually done any work yet. Here's what to do next:
- If you plan to use a database, edit the DATABASES setting in project/settings.py.
- Start your first app by running python manage.py startapp [appname].
You're seeing this message because you have DEBUG = True in your Django settings file and you haven't configured any URLs. Get to work!
Before we can start writing our web app, we have to make some configurations to our project and lets do that quick. Open up testProject/settings.py file in your favourite text editor, [ mine is geany ]. Change the line:
ADMINS = (to
# ('Your Name', 'your_email@example.com'),
)
ADMINS = (You should use your name and email. These information are the webmasters information. Next step is to setup the database configuration. For this change
# ('Paras Nath Chaudhary', 'opnchaudhary@gmail.com'),
)
DATABASES = {to
'default': {
'ENGINE': 'django.db.backends',
'NAME': '',
'USER': '', 'PASSWORD': '',
'HOST': '',
'PORT': '',
}
}
DATABASES = {We are going to use the sqlite driver for it will be easy for us during development phase and for production purpose just changing the configuration here it will be deployable to any of the supported database systems. For now lets just get stick with sqlite3. Leave other settings as it is and lets skip to the line:
{
'ENGINE': 'django.db.backends.sqlite3',
'NAME': 'mydatabase.db',
'USER': '',
'PASSWORD': '',
'HOST': '',
'PORT': '',
}
}
INSTALLED_APPS = (and change it to:
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
# Uncomment the next line to enable the admin:
#'django.contrib.admin',
# Uncomment the next line to enable admin documentation:
# 'django.contrib.admindocs',
)
INSTALLED_APPS = (Finally save the file.
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
# Uncomment the next line to enable the admin:
'django.contrib.admin',
# Uncomment the next line to enable admin documentation:
# 'django.contrib.admindocs',
)
And its time to run another command
$ python manage.py syncdbSomething like
Creating tables ...should appear in your screen type 'yes' and hit enter. Then you will be getting consequently:
Creating table auth_permission
Creating table auth_group_permissions
Creating table auth_group
Creating table auth_user_user_permissions
Creating table auth_user_groups
Creating table auth_user
Creating table django_content_type
Creating table django_session
Creating table django_site
You just installed Django's auth system, which means you don't have any superusers defined.
Would you like to create one now? (yes/no):
Username (leave blank to use 'root'): rooti.e. you must supply username , email and password as it is shown above. NOTE that the password you type won't be visible to you. On completion you should see:
E-mail address: opnchaudhary@gmail.com
Password:
Password (again):
Superuser created successfully.
Installing custom SQL ...
Installing indexes ...
Installed 0 object(s) from 0 fixture(s)
Comments
Post a Comment