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:
$ django-admin.py startproject testProject
This 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 testProject
and run the project using the command:
$ python manage.py runserver 
In the command line, you should see something like:
Validating models...

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.
This means our project has been successfully created and we can open the url
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 = (

# ('Your Name', 'your_email@example.com'),

)

to
ADMINS = (

# ('Paras Nath Chaudhary', 'opnchaudhary@gmail.com'),

)
You should use your name and email. These information are the webmasters information. Next step is to setup the database configuration. For this change
DATABASES = {
'default': {
'ENGINE': 'django.db.backends',
'NAME': '',
'USER': '', 'PASSWORD': '',
'HOST': '',
'PORT': '',
}
}
to
DATABASES = {
{
'ENGINE': 'django.db.backends.sqlite3',
'NAME': 'mydatabase.db',
'USER': '',
'PASSWORD': '',
'HOST': '',
'PORT': '',
}
}
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:
INSTALLED_APPS = (
'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 change it to:
INSTALLED_APPS = (
'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',
)
Finally save the file.
And its time to run another command
 $ python manage.py syncdb 
Something like
Creating tables ...
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):


should appear in your screen type 'yes' and hit enter.  Then you will be getting consequently:
Username (leave blank to use 'root'): root
E-mail address: opnchaudhary@gmail.com
Password:
Password (again):
i.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:
Superuser created successfully.
Installing custom SQL ...
Installing indexes ...
Installed 0 object(s) from 0 fixture(s)

Comments

Popular posts from this blog

Automate file upload in Selenium IDE

How To Install and Configure Nextcloud