Run the Django server on Pycharm, and create an app method

Source: Internet
Author: User
Tags django server

Installing Django

Download the Django package and unzip it.

CMD into the decompression path.

Execute: Python setup.py install

Add Environment variables:

C:\Python27\Scripts

Test if Django is installed successfully

Shell

Import Django

Django. VERSION

Import Django into the project

CMD into the project path

Execute django-admin.py Startproject project name

Run the development server

Project Django path under Python manage.py runserver

Or

Python manage.py Runserver 8000

Or

By specifying an IP address, you can tell the server – Allow non-local connection access. This feature is especially useful if you want to share the same development site with other developers. The ' 0.0.0.0 ' IP address tells the server to listen on any network interface.

Python manage.py runserver 0.0.0.0:8000 The above is the Django server running at CMD Terminal next to run on the server side on Pycharm:If you run the manage.py program directly, you will be prompted with a lot of things, that is, the hint is not passed parameters. So on the pycharm on the parameters to run: Operate as follows open the manage.py file in the upper right corner of the Pycharm click Edit Configurations Editing configuration parameter points Open after the following dialog box, in scrip parameters  In the corresponding dialog box, enter the configuration parameters Runserver 0.0.0.0:8000. When the configuration is complete, click OK to finish. After configuring the above information, press CTRL+SHIFT+F10 to run the manage.py file: The following results appear D:\Python27\python.exe d:/djangotext01/manage.py runserver 0.0.0.0:8000
Performing system checks ...

System Check identified no issues (0 silenced).

You have unapplied migrations; Your app properly until they is applied.
Run ' python manage.py migrate ' to apply them.
July 26, 2015-22:10:52
Django version 1.8.2, using Settings ' djangotext01.settings '
Starting development Server at Http://0.0.0.0:8000/
Quit the server with Ctrl-break.
d:\python27\lib\site-packages\django-1.8.2-py2.7.egg\django\utils\translation\__init__.py:146: Removedindjango19warning:the use of the language code ' ZH-CN ' is deprecated. Please use the ' Zh-hans ' translation instead.
The return _trans.activate (language) configuration is complete and will default to the above configuration parameters when it is started later. After configuring the above information, enter http://127.0.0.1:8000 in the browser to return the following results: Create a Django app

Let's take a look at some of the necessary concepts first. What does Django call an APP?

We've created project, so what's the difference between project and APP? The difference is that one is to configure the other is the code:

A project contains a number of Django apps and their configuration.

Technically, project's role is to provide configuration files, such as where to define database connection information, the list of installed apps, Template_dirs, and so on.

An app is a set of Django features, often including models and views, in the way Python's package structure exists.

For example, Django itself has some apps, such as a comment system and an automated management interface. One key point of the app is that they are easily ported to other project and reused by multiple project.

Create an App

Under the "Pythonproject" project file, enter the following command to create the "Nowamagic" app:

1 python manage.py startapp nowamagic

This command does not output anything, it only creates a nowamagic directory in the Pythonproject directory. Let's take a look at the contents of this directory:

1 nowamagic/
2     __init__.py
3     models.py
4     tests.py
5     views.py

This directory contains the model and view of the app.

Use your favorite text editor to see the contents of the models.py and views.py files. They are all empty except for an import in the models.py. This is the foundation of your Django app.

    • There are no quick sets of rules for how to structure Django code. If you're just building a simple Web site, you probably just need an app, but if it's a complex site with many unrelated modules, such as e-commerce and community sites, you might want to divide the modules into different apps for later reuse.

Yes, you don't have to create apps, which should be proven by examples of view functions we've written before. In those cases, we simply created a file called views.py, wrote some functions, and set the mappings for each function in the urlconf. These situations do not require the use of apps.

However, the system has a convention for apps: If you use a Django database layer (model), you must create a Django app. The model must be stored in the apps. So, in order to start building our model, we have to create a new app.

You'll find out later how much convenience the app will bring to us.

Run the Django server on Pycharm, and create an app method

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.