In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Network Security >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains "the introduction of Django framework". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn the introduction to the Django framework.
Python has become very popular these years, and the web framework has emerged as the times require. Django is one of the typical web frameworks.
Django complies with the copyright of BSD, first released in July 2005, and released the first official version 1.0 in September 2008. at this time, domestic Java is in full swing, web frameworks emerge in endlessly, and Python is relatively minority. Unexpectedly, after a few years, I caught up with big data's express train. There is Python in the data analysis. Devops is very popular in recent years, and the automation platform is still the same python framework, basically Django, so when it comes to Django, many people are no strangers.
I took the time to study briefly and found that it was in line with my expectations. The reason will be explained later.
Because Python is cross-platform, under windows, linux is compatible, so for convenience, I tested it directly on windows. Tell me a few holes.
One is that after downloading the installation package, the Python version is 2.7. if the version that comes with Linux is 2.6 or lower. There are two major versions of Python, 2.7and 3.0. although they are high and low versions, there is a big difference. So there will be a certain compatibility gap in the version of Django.
For example, I downloaded the latest version of Python2.7, the relatively new version of Django, and threw an error when I installed Django.
D:django-masterdjango-master > python setup.py install
Traceback (most recent call last):
File "setup.py", line 5, in
...
File "D:programspython2.7Libsocket.py", line 47, in
Import _ socket
ImportError: DLL load failed: the specified module was not found.
I read a lot of information on this question, and finally realized that it should be the incompatibility of the version.
So I decisively downloaded Python 3.6and tried it again.
So a basic compatibility list is shown below to avoid a lot of detours.
Django version Python version 1.82.7,3.2,3.3,3.4,3.51.9, 1.102.7,3.4,3.51.112.7,3.4,3.5,3.62.03.5 +
To install Django is to call python setup.py install directly under the downloaded installation directory.
Verify that Django is installed successfully, or you can introduce this library into python to test that it is working.
> import django
> > django.get_version ()
'2.1'
> > >
If you want to create a project, such as testdj, you can use a unified command line django-admin.
Django-admin startproject testdj
If you need to start the service, use python in the project directory to invoke the manage.py file in the directory.
Of course, if it is used as a test environment, there is no problem with this. If it is used in an online environment, you need to use a more professional approach, such as using the server for nginx.
If it is a version 2.0 or later Django, the welcome screen after startup looks like this.
The lower version is a little simpler, but for most of our applications, Python2.7 is still widely used, so the matching version of Django remains within a limited range.
Of course, this is a completely blank template, there is no content, we can have a helloworld
Under the project directory, create a Python file, view.py, using HttpResponse to return the data.
From django.http import HttpResponse
Def hello (request):
Return HttpResponse ("Hello world! jeanron100")
On the other hand, the reverse of the page information is done by using urls.py.
From django.conf.urls import url
From. Import view
Urlpatterns = [
Url (r'^ $', view.hello)
]
It can also be used to separate data from the view on this basis. The data is in the html file, the view is modified in view.py, and the mapping between the two is linked through the template file.
For example, the content of the data file hello.html is as follows, which is replaced by a variable.
{{hello}}
And the view information is modified view.py, the content is as follows, the original HttpResponse is changed to render.
From django.shortcuts import render
Def hello (request):
Context = {}
Context ['hello'] =' Hello Worldwide'
Return render (request, 'hello.html', context)
How this hello.html file is mapped is linked by a specified directory, for example, the directory specified as templates,hello.html is placed in this directory.
You need to modify the original settings.py file, modify part of the directory and specify it to the templates directory.
TEMPLATES= [{'BACKEND':' django.template.backends.django.DjangoTemplates', 'DIRS': [BASE_DIR+ "/ templates",], # modify location
.
The modified value is also based on the mapping relationship, for example, the value of the variable hello is bit hello World!
At this point, I believe you have a deeper understanding of the "introduction to the Django framework". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.