Django + eclipse Configuration

Source: Internet
Author: User
Tags install django

From http://www.djangoproject.com/download
Download Django and decompress it to the D:/Django directory.

Enter Python setup. py install under Django Directory D:/Django. This command will install Django under site-package and set SYS. path at the same time.

Django-admin.py setting method:

1.
Django mainly uses the django-admin.py script to manage the project, by default, Django is installed in the python installation directory, the General
Yes: In the $ Python/lib/Site-packages/Django directory, we need to enter a long
Address: "D:/python25/lib/Site-packages/Django/bin/django-admin.py" to call, in order to facilitate the call
Django-admin.py, we add the directory where the django-admin.py is located to the path of the system so that Django-
Admin. py can call this management script without entering a long address.

2. Set the pythoninstalldir/scripts directory in path, because if you use the standard
Python installation method, Django will automatically install the django-admin.py under the scripts directory. In this way, once you set
Scripts in the path, you can execute the django-admin.py in any directory under the command line.

Open a new command prompt window through cmd and enter "django-admin.py help" directly, the corresponding prompt information of Django will appear.

Then, run the django-admin.py startproject pydemo command, create a project named pydemo under the current directory, open the directory of the new project, you will find the following four files:

_ Init _. py: use this project directory as a python package.

Manage. py: You can manage this project under the command line.

Settings. py: configuration file of this project.

URLs. py: defines the URL route table in the Django project and specifies the correspondence between the URL and the called class.

Run the python manage command in the directory of the current project. PY runserver can start the current project. The project listens to port 8000 by default, and http: // localhost: 8000/is opened to view the Django welcome page.

In Django, most applications exist in the form of apps, but must they be added? Not necessarily. In Django
In, each app is a sub-package. In actual calls, you must use URL dispatch to map the URL to the module method. This is Django
But it is also a little troublesome. Without it, you cannot publish a function. If there is a default Simple ing method in Django, this will greatly improve
Django entry-level experience. However, in a relatively large project, using an app is still a good method. It can split the project functions to facilitate organization and code reuse.

Therefore, according to the URL dispatch mechanism, we only need to ensure that Django can find the method to call in the correct place. Then we will not create an app at all.

Create a file helloworld. py in the newtest directory with the following content:

From Django. Http import httpresponse

Def index (request ):

Return httpresponse ("Hello, Django .")

Modify URLs. py,

From Django. conf. URLs. defaults import *

Urlpatterns = patterns ('',

# Example:

# (R' ^ newtest/', include ('newtest. Apps. Foo. URLs. foo ')),

(R' ^ $ ', 'newtest. helloworld. Index '),

# Uncomment this for admin:

# (R' ^ admin/', include ('django. contrib. admin. urls ')),

)

Okay. Saved. The above R' ^ $ 'is used to match an empty string, such as http: // localhost: 8000 /. If the Web server is started, refresh the page and output hello, Django ..

Configuration in Eclipse:

1. First create a python project, eclipse
IDE-file-New-other-pydev-select pydev
Project-select a project name (for example, pydemo)-select a path, for example, D:/workspace-select a Python version suitable for you (My is
2.5)-"remove the following check box. Do not create a SRC file-" select interpreter (Interpreter) and select the python file already set above.
Interpreter-"finish.
2. Copy the generated Django project directory to the directory of the project just created by eclipse. Back to the elicpse
IDE-"in pydev
In the package view, right-click the new project and select "refresh" from the pop-up menu to view the Django project. You can add or delete files and directories
Right-click the menu.
3. Right-click pydev project-> properties-> select pydev-> pythonpath-> Add the src directory (project file path) to the project code-> OK

4. Configure the pydev project: select the project name of pydev-run menu-Open Run
Right-click "dialog-" Python run-"and choose" New-"to write the project name in the main panel, and load the project name and main
Module, main module choose manage. py-> In the augement panel, argument must be runserver
-- Noreload: Add the following working directory to your base directory.

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.