geodjango seven study notes (7.30 organize local notes uploaded to the network)

The first day to the present, at the beginning of the tail, I remember writing a study notes,
Has been setting up the development environment, using a pycharm environment is native to the existing interpreter python3.7
 
The next thing to do is to create a new geodjango project (python console / terminal, see the documentation https://docs.djangoproject.com/en/2.1/ref/contrib/gis/tutorial/#setting-up
(About python console / terminal,
Wherein, called the Python Console Python console, i.e. the Python interactive mode; Terminal is called a terminal, i.e., command-line mode.
There are two main Python interactive mode: CPython used as >>> prompt, and with IPython In [ID]: as a prompt.
Python interactive mode can directly enter the code, and then executed, and immediately get results, so Python interactive mode is mainly used for debugging Python code.
CMD command line mode and systems (command prompt), as the system can run various commands. )
), Configuration postgis, use this space to find out what is the difference and database before
 
You know what to do next: as long as the site is running out, setting up the basic framework, the latter function is not difficult to achieve, write a few needs, and then move it a little brick, come on baby
 
The next progress

image

 
How to build a website and publish with django, how to improve the front end, how to combine geoserver in geodjango, these problems can be solved
 
In-depth understanding of web frameworks
image
 
 
Referring mvc asp.net web frame mode, processing logic constructs
 
About mvc and mtv
MVC design pattern and MTV:
在目前基于Python语言的几十个Web开发框架中,几乎所有的全栈框架都强制或引导开发者使用MVC设计模式。所谓全栈框架,是指除了封装网络和线程操作,还提供HTTP、数据库读写管理、HTML模板引擎等一系列功能的Web框架,比如Django、Tornado和Flask。
MVC设计模式:
最早由 Trygve Teenskaug 在1978年提出,上世纪80年代是程序语言Smalltalk的一种内部架构。后来MVC被其他领域借鉴,成为了软件工程中的一种软件架构模式。MVC把Web框架分为3个基础部分:
模型(Model) :用于封装与应用程序的业务逻辑相关的数据及对数据的处理方法,是Web应用程序中用于处理应用程序的数据逻辑的部分,Model只提供功能性的接口,通过这些接口可以获取Model的所有功能。白话说,这个模块就是Web框架和数据库的交互层。
视图(View) :负责数据的显示和呈现,是对用户的直接输出。
控制器(Controller) :负责从用户端收集用户的输入,可以看成提供View的反向功能。
这三个部分互相独立,但又相互联系,使得改进和升级界面及用户交互流程,在Web开发过程任务分配时,不需要重写业务逻辑及数据访问代码。
MVC在Python之外的语言中也有广泛应用,例如VC++的MFC,Java的Structs及Spring、C#的.NET开发框架,都非常有名。
MTV设计模式:
Django对传统的MVC设计模式进行了修改,将视图分成View模块和Template模块两部分,将动态的逻辑处理与静态的页面展现分离开。而Model采用了ORM技术,将关系型数据库表抽象成面向对象的Python类,将表操作转换成类操作,避免了复杂的SQL语句编写。MTV和MVC本质上是一样的。
模型(Model) :和MVC中的定义一样
模板(Template) :将数据与HTML语言结合起来的引擎
视图(View) :负责实际的业务逻辑实现
Django的MTV模型组织可参考下图所示:
 
 
 
 
image
 
关于ajax
二、 AJAX
我们知道,在前端的世界,有一种叫做AJAX的东西,也就是“Asynchronous Javascript And XML”(异步 JavaScript 和 XML),经常被用来在不刷新页面的情况下,提交和请求数据。如果我们的Django服务器接收的是一个通过AJAX发送过来的POST请求的话,那么将很麻烦。
为什么?因为AJAX中,没有办法像form表单中那样携带 {% csrf_token %} 令牌。
那怎么办呢?
好办!在你的前端模版的JavaScript代码处,添加下面的代码:
// using jQuery function getCookie(name) { var cookieValue = null ; if ( document .cookie && document .cookie !== '' ) { var cookies = document .cookie.split( ';' ); for ( var i = 0 ; i < cookies.length; i ++ ) { var cookie = jQuery.trim(cookies[i]); // Does this cookie string begin with the name we want? if (cookie.substring( 0 , name.length + 1 ) === (name + '=' )) { cookieValue = decodeURIComponent (cookie.substring(name.length + 1 )); break ; } } } return cookieValue; } var csrftoken = getCookie( 'csrftoken' ); function csrfSafeMethod(method) { // 这些HTTP方法不要求CSRF包含 return ( /^(GET|HEAD|OPTIONS|TRACE)$/ .test(method)); } $.ajaxSetup({ beforeSend : function (xhr, settings) { if ( ! csrfSafeMethod(settings.type) && !this .crossDomain) { xhr.setRequestHeader( "X-CSRFToken" , csrftoken); } } });
上面代码的作用就是让你的ajax的POST方法带上CSRF需要的令牌,它依赖Jquery库,必须提前加载Jquery。这是Django官方提供的解决方案哦,^-^。
 
 
 
目前遇到的技术难题:单看geodjango文档,无法理解里面的操作如何与前端结合,或者说不知道前端怎么写,写哪里 ,这些技术该怎么用,我要做的很简单,就是搭一个前端界面,用openlayers或者inmap导入地图(这两者的区别在于inmap侧重大数据可视化,都是js库,还有EXT组件库,现在就就是不是很明确这些库的区别和实现的功能,webgis课没花多大精力留下的坑,卧槽),在此基础上添加功能,我也不知道这些功能如何添加上去
 
 
过程中发现的严重问题:你的学习缺少思路的整理与梳理,技术可以不深究,但是逻辑的分支是得条条走通的,
 
 
关于django的orm,目前接触到的最大的一个特点: 并带有权限控制的增删改查界面,而且可以通过ORM为它生成的API来做到定制化的更新,比如直接读某个wiki上的配置,自动的写入数据库,伪代码如下:,就是把数据库结构对象化,自动实现连接数据库的增删改查,我不知道其他web框架是怎么搞数据库的,反很像python的这个高度面对对象很牛逼了,再用makemigration命令手动在数据库中生成数据表,该命令执行后返回一个initial.py文件,里面保存了数据迁移工作,创建了数据库模型对象,再使用migrate命令,创建真实的数据表,admin是一个自带app,可当作数据库管理后台
伪代码:
import pandas as pd
settings = pd.read_html('http://某个gitlab的README 或者 某个redmine wiki')
settings = clean(settings)
update(settings)
 
 
关于初步架构视图与url调用
def register (request): pass return render(request, 'login/register.html' ) def logout (request): pass return redirect( "/login/" )
 
 
今天发现耳机里放的音乐声音不能太大,我的金脑需要轻悠的旋律滋养,别给震坏了,眼神里散发的全是智慧的光芒。噗噗噗二逼
 
 
接下来的需求分析:
 
 
On the basis of realization of the full-screen map, add a floating box on the page, add positioning to the current button, button collections, a collection (to locate the current position, latitude and longitude to obtain location information for global variables, pop business data entry interface, database design is the type of shops, cardiac index, business name, the interface includes Notepad window that pops up at the same time, latitude and longitude information to map incoming punctuation array, array shops feature has been included in the national data, used the example screen display) to do, and other basic keys, block style suspension, contained within
 
There modify database problems, click the icon pop-up shops have been suspended boxes, shops can be achieved delete, modify notes, etc., move the mouse to the icon positions suspension box displays basic information
 
 
 
How to achieve? technical problem:
 
Specific functions implemented ideas:
First, there is a sample point, these points, the mouse floating pop-up message box, as regional specialties sample information, to engage in a database or the addition of a key Favorite keys in the map div, I am his mother did not know how to connect the front end of django to the background, anyway, click, automatically get the current position, the pop-up edit box, enter a user name, type shops, cardiac index, as well as mood record, click submit back-end database entry, close the pop, refresh the map display, complete, one problem now is the layer where the data is entered manually, imported from a database I want to do, this might not be a problem, that form will be able to solve the biggest problem now is the front end of the dog,
 
 
 

Guess you like

Origin www.cnblogs.com/heikejingxiao/p/11269348.html