Developing WEB sites using Django and Python

Source: Internet
Author: User

About Eclipse Configuration Pydev, please readers themselves Baidu, here Dapeng brother directly about the above work after the Django installation and configuration:

First download the Django installation package: shaped like django-*.*.*.tar.gz (eg. django-1.1.1.tar.gz)

1. Installation

Unzip Django, I am unzip to python27, there is a setyp.py file in the Django directory, open the Run window to install.


2, in order to facilitate the development, we will then configure the system variables

Path= C:\Python27\Scripts; C:\Python27\Lib\site-packages\django\bin

3. Test if Django is installed successfully

First look at whether C:\Python27\Lib\site-packages\django\bin exists, and then create a project

django-admin.py Startproject Djproject

After running manage.py runserver, enter http://127.0.0.1:8000/in the browser address bar


The above screen appears, that is, the installation is successful

Create the Djproject module above, copy the Djproject directory in the C:\Python27\Lib\site-packages\django\bin to your Eclipse working directory Dapeng is (F:\ME85), Then launch eclipse, click "File", "New", "Project ..." and you will see the following screen

Select "Pydev Project" and click "Next"

Create a project with Djproject, the path to your original generated project directory, Grammar version select 2.7, interpreter corresponding to choose Python27, cancel the system generated SRC directory, click "Finish" to complete the creation, Right click on the project catalog and select "Refresh" and you will be in the original generated file.

Now let's do some testing, first to set up a subset


Refresh the project catalog again


To make Django aware of the existence of a new application, you also need to add an entry to the Installed_apps in the settings.py file. For this job bulletin board application, we must add the string djproject.jobs:


Then to the database, Django provides its own object-relational data mapping component (Object-relational Mapper,orm) library, which can support dynamic database access through the Python object interface. This Python interface is very useful and powerful, but if you need it, you have the flexibility to use SQL instead of using this interface.

ORM is currently available for PostgreSQL, MySQL, SQLite, and Microsoft? Support for SQL database.

This example uses SQLite as a background database. SQLite is a lightweight database that does not need to be configured to exist on disk in the form of a simple file.

Go to sqlite official website to download the file like Sqlite-shell-win32-x86-3080600.zip, unzip can.

before using this model, the database needs to be configured in the settings file. SQLite only needs to specify the database engine and database name.


This Job bulletin board application has two types of objects: location and job. The location contains the city, state (optional), and country fields. The Job contains the location, title, description, and publish Date fields.


To view the database schema using the manage.py SQL command


In order to initialize and install this model, run the database command syncdb:

Note that the SYNCDB command requires us to create a super user account. This is because the Django.contrib.auth application (which provides basic user authentication functionality) is provided by default in the Installed_apps settings. The super User name and password are used to log in to the administrative tools that are described in the next section. Remember, this is a Django superuser, not a super user of the system.


One of Django's biggest selling points is its first-class management interface. This tool is designed according to the idea of the end user. It provides a lot of data entry tools for our projects.

The administration tool is an application that Django provides. As with the jobs application, it must be installed before it can be used. The first step is to add the application's module (django.contrib.admin) to the Installed_apps settings:


Enables management tools to be used by urls.py


This management application has its own database model, but it also needs to be installed. We can use the SYNCDB command again to complete this process:

Using a test server to view Administrative tools

you can now use Http://localhost:8000/admin Start the Administration tool and log in using the Superuser account you created earlier. We note that there are no modules available at this time.


to enable a class to be accessed through administrative tools, we need to create a Admin sub-class. You can then customize how each class is managed by adding class properties to this subclass. The list shows how to add the location class to this management tool.

Class location (meta. Model):

...

Class Admin:

List_display = ("City", "state", "country")

Then refresh the page to find the following:

Then create the admin.py file under jobs below:

from Django.contrib import Admin

from jobs.models import location,Job

Admin.site.register (location)

Admin.site.register (Job)

Change the settings in urls.py as follows:


All right, then. 8000 the interface will appear as follows, enter the previous user name and password to enter:

Admin interface of the Chinese also relatively simple to settings.py in the en-us to ZH-CN can be. After the Han Dynasty, the following:


Developing WEB sites using Django and Python

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.