post

Django contenttypes 组件

不打扰是莪最后的温柔 提交于 2020-02-05 05:35:22
介绍 Django包含一个contenttypes应用程序(app),可以跟踪Django项目中安装的所有模型(Model),提供用于处理模型的高级通用接口。 Contenttypes应用的核心是ContentType模型,位于django.contrib.contenttypes.models.ContentType。 ContentType的实例表示并保存项目中安装的模型的信息,每当有新的模型时会自动创建新的ContentType实例。 只要使用django-admin startproject 命令创建的Django项目(PyCharm创建Django项目同理),默认都会在settings.py的INSTALLED_APPS列表中安装好django.contrib.contenttypes。 我们执行了数据迁移命令之后,会自动在数据库中创建一个名为django_content_type的表。 表结构如下图所示: 其中,app_label字段存储了APP的名称,model字段存储了APP下的具体的模型类的名称。 应用场景 我们在网上po一段散文诗也可以po一张旅途的风景图,文字可以被评论,图片也可以被评论。我们需要在数据库中建表存储这些数据,我们可能会设计出下面这样的表结构。 class Post(models.Model): """帖子表""" author = models

Django contenttypes组件

半世苍凉 提交于 2020-02-05 05:33:57
contenttypes组件 介绍 Django包含一个contenttypes应用程序(app),可以跟踪Django项目中安装的所有模型(Model),提供用于处理模型的高级通用接口。 Contenttypes应用的核心是ContentType模型,位于django.contrib.contenttypes.models.ContentType。 ContentType的实例表示并保存项目中安装的模型的信息,每当有新的模型时会自动创建新的ContentType实例。 只要使用django-admin startproject 命令创建的Django项目(PyCharm创建Django项目同理),默认都会在settings.py的INSTALLED_APPS列表中安装好django.contrib.contenttypes。 我们执行了数据迁移命令之后,会自动在数据库中创建一个名为django_content_type的表。 表结构如下图所示: 其中,app_label字段存储了APP的名称,model字段存储了APP下的具体的模型类的名称。 应用场景 我们在网上po一段散文诗也可以po一张旅途的风景图,文字可以被评论,图片也可以被评论。我们需要在数据库中建表存储这些数据,我们可能会设计出下面这样的表结构。 class Post(models.Model): """帖子表"""

Servlet与Jsp学习笔记--2、POST HTTP Request

ε祈祈猫儿з 提交于 2020-02-05 00:33:30
Problem POST request. Solution Use the ServletRequest.getParameter(String name) , getParameterMap( ) , getParameterNames( ) , or getParameterValues(String name) methods in the servlet's doPost method Code(servlet) import java.io.IOException; import java.io.PrintWriter; import java.util.Enumeration; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.util.Map; import java.util.Iterator; import java.util.Map.Entry; public class FirstServlet extends HttpServlet {

jquery post json data to PHP file

被刻印的时光 ゝ 提交于 2020-02-04 23:07:26
问题 I have a click event where I compose a json data , then I want to POST it to a PHP file for processing . But something goes wrong. My PHP file is simplified for now looking like this: <?php header('Content-Type: application/json'); var_dump($_POST); ?> And the code for POST-ing looks like this: // myarray is: var myarray = new Array(); // and it gets populated above this code var strObj = JSON.stringify(myarray); alert(strObj); // so far I get the alert containing valid JSON text $.ajax ({

jquery post json data to PHP file

帅比萌擦擦* 提交于 2020-02-04 23:05:49
问题 I have a click event where I compose a json data , then I want to POST it to a PHP file for processing . But something goes wrong. My PHP file is simplified for now looking like this: <?php header('Content-Type: application/json'); var_dump($_POST); ?> And the code for POST-ing looks like this: // myarray is: var myarray = new Array(); // and it gets populated above this code var strObj = JSON.stringify(myarray); alert(strObj); // so far I get the alert containing valid JSON text $.ajax ({

jquery post json data to PHP file

江枫思渺然 提交于 2020-02-04 23:05:46
问题 I have a click event where I compose a json data , then I want to POST it to a PHP file for processing . But something goes wrong. My PHP file is simplified for now looking like this: <?php header('Content-Type: application/json'); var_dump($_POST); ?> And the code for POST-ing looks like this: // myarray is: var myarray = new Array(); // and it gets populated above this code var strObj = JSON.stringify(myarray); alert(strObj); // so far I get the alert containing valid JSON text $.ajax ({

jquery post json data to PHP file

荒凉一梦 提交于 2020-02-04 23:04:27
问题 I have a click event where I compose a json data , then I want to POST it to a PHP file for processing . But something goes wrong. My PHP file is simplified for now looking like this: <?php header('Content-Type: application/json'); var_dump($_POST); ?> And the code for POST-ing looks like this: // myarray is: var myarray = new Array(); // and it gets populated above this code var strObj = JSON.stringify(myarray); alert(strObj); // so far I get the alert containing valid JSON text $.ajax ({

Django:视图views(二)

走远了吗. 提交于 2020-02-04 22:40:38
把request对象和response对象原理流程写一下 request对象 服务器端接收到http 协议的请求,会根据报文信息构建 HttpRequest 对象 通过第一个参数,把该对象传递给视图函数 Request 对象包含了如下的属性: path 属性:字符串。表示请求的页面的完整路径。 method 属性:请求的方法。 GET 或 POST 测试方法: 添加路由 booktest/urls.py urlpatterns = [ url('^$',views.index), # 路由到views.py中的index()函数 url('^index', views.index, name="index"), url('^(\d+)$', views.integer), url('^(?P<p2>\d+)/(?P<p3>\d+)/(?P<p1>\d+)$', views.date), url('^req$', views.req), ] 添加视图 booktest/views.py def req(request): print("path:", request.path) print("method:", request.method) return render(request, 'booktest/req.html') 添加模板 在templates/booktest/

ElasticSearch-入门学习

我只是一个虾纸丫 提交于 2020-02-04 21:53:38
基本概念 索引 :含有相同属性的文档集合 --相当于database 类型 :索引可以定义一个或多个类型,文档必须属于一个类型 --相当于table 文档 :文档是可以被索引的基本数据单位,是最小的存储单位 --相当于row RESTFul API 索引创建: http://localhost:9200/people put { "settings" : { "index" : { "number_of_shards" : 5, "number_of_replicas" : 1 } } } 在索引上创建类型映射 http://localhost:9200/people/man/_mappings put/post { "properties" : { "name" : { "type" : "text" } , "country" : { "type" : "keyword" } , "age" : { "type" : "integer" } , "date" : { "type" : "date" , "format" : "yyyy-MM-dd HH:mm:ss" } } } 一次性创建索引和类型映射 http://localhost:9200/people put { "settings" : { "index" : { "number_of_shards" : 5,

WebAPI规范设计——违RESTful

廉价感情. 提交于 2020-02-04 16:01:22
本文首先简单介绍了几种API设计风格(RPC、REST、GraphQL),然后根据实现项目经验提出WebAPI规范设计思路,一些地方明显违反了RESTful风格,供大家参考! 一、几种设计风格介绍 1.1 RPC 这是最常见的方式,RPC说的是本地调用远程的方法,面向的是过程,估计超过50%的API是这种分格的。 RPC形式的API组织形态是类和方法,或者说领域和行为。 因此API的命名往往是一个动词,比如 GetUserInfo,CreateUser 。 因为URI会非常多而且往往没有一些约定规范,所以需要有详细的文档。 也是因为无拘无束,HTTP方法基本只用GET和POST,设计起来比较简单。 1.2 REST REST架构风格有四个级别的成熟度: 级别 0:定义一个 URI,所有操作是对此 URI 发出的 POST 请求。 级别 1:为各个资源单独创建 URI。 级别 2:使用 HTTP 方法来定义对资源执行的操作。 级别 3:使用超媒体(HATEOAS)。 级别0其实就是类RPC的风格,级别3是真正的REST,大多数号称REST的API在级别2。REST实现一些要点包括: REST形式的API组织形态是资源和实体,一切围绕资源(级别1的要点)。 会定义一些标准方法(级别2的要点),然后把标准方法映射到实现(比如HTTP Method): GET:获取资源详情或资源列表