Python creates a simple Django tutorial for Beginners

Source: Internet
Author: User
Tags install django pip install django django tutorial

Learn the Python language in your own interest and create a most basic Django project, not to mention it. directly on the process

Django is an open-source Web application framework, written by Python, before we start using Django, first install the Python development environment

Python installation (installed can be skipped)

To install Python you only need to go to the official website (https://www.python.org/) to download the installation files, and then directly to the idiot-type installation.

What I'm directly choosing here is the latest version of Python, 3.6.5, for development.

After the download is complete, click Install, you need to set up the Python environment variable after installation, generally choose Add to path option during installation, the program will automatically set the python environment variable, do not need to manually add environment variables, save some time.

After installing the Python development environment, we cmd open the command line and enter "Python" (below)

When prompted as shown, it indicates that our Python development environment has been successfully installed, and if the command line shows that Python is not an internal or external command and is not a running program, then manually add Python to the environment variable

The following is an example of a win7 system

Computer--right---Attribute Select Advanced System Properties

Select the environment variable, select Path, add the Python installation path to the back, remember to use;

After we install Python, the next step is to install the Django Framework we need to develop, and we'll install the Django framework via PIP, because we're installing the latest version of Python and directly opening the command line for PIP, the following results will appear

Description We can install the framework directly via PIP install Django

After the installation is complete, open the command line

To view the Djaogo version of the installation, the version number indicates that our Python has been successfully installed

Create a Django Project

After all the configuration of the development environment, open the editor, here I am using the Pycharm Editor, here is to note that in the use of this development tool for development is that we want to choose the Professional version of the download installation, because when choosing the free version of the development, the editor is not the choice to create djaogo this option, So here we have to choose the Professional version of the download installation for development

When the editor download installation is complete, we're ready to start creating the simplest Django project.

Open the editor and select File--New project to select a Django project

After setting up, click Create, after the creation is complete the directory is as follows

I created a new DJ directory, which also has a DJ directory, this subdirectory is a set of project settings settings.py file, the total URLs configuration file urls.py As well as the wsgi.py file used to deploy the server, __init__.py is the directory structure of the Python package that must be associated with the call.

We're going to create another app, called the CMDB.

After the command line we enter the Python manage.py Startapp CMDB, it is important to note that the Diango installation path should also be added to the environment variables inside the system, otherwise it will be an error

Django will then create another new application CMDB.

Add our newly defined app to the Install_apps in settings.py

Modify dj/dj/settings.py

INSTALLED_APPS =(

     ‘django.contrib.admin‘ ,      ‘django.contrib.auth‘ ,      ‘django.contrib.contenttypes‘ ,      ‘django.contrib.sessions‘ ,      ‘django.contrib.messages‘ ,      ‘django.contrib.staticfiles‘ ,      ‘cmdb‘ , )If you don't add the new app to Install_apps, Django can't automatically find the app. template file(Files under app-name/templates/) and Static Files(Files in app-name/static/) Next we open the CMDB project, open the views.py input from django.http  import HttpResponse def index(request):      return HttpResponse( "Hello world" )Next we define the view function related URLs to open the DJ project under the urls.py
From Django.contrib Import admin
From Django.urls Import path
From CMDB import views as Learn_views
Urlpatterns = [
Path (' home/', Learn_views.index),
]
Then select this project

Here we can set the access port
After setting up the click Run, you can see that our project has been running in the local


Next we open the browser, enter the port number, enter the access path, you can see in the browser we can access to the page
This is how a simple project built by the Django framework is done, how does it feel so easy!!
You'll also write a few simple tutorials on Django ...

Python creates a simple Django tutorial for Beginners

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.