PYTHON August 19, 2018

django数据models基础

Words count 9.2k Reading time 8 mins.

定义一个Persion模型类,包括first_name、last_name字段

from django.db import models

class Person(models.Model):
    first_name...
Read article

PYTHON August 19, 2018

django数据models基础

Words count 9.2k Reading time 8 mins.

定义一个Persion模型类,包括first_name、last_name字段

from django.db import models

class Person(models.Model):
    first_name = models.CharField(max_length=30)
    last_name = models.CharField(max_length=30)

first_name 和last_name是模型的领域。每个字段被指定为一个类属性,每个属性映射到一个数据库列,上面的Persion...

Read article

PYTHON August 19, 2018

django配置settings详解

Words count 4.3k Reading time 4 mins.

项目根目录:

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

项目安全码:

SECRET_KEY = ')b)3406p#v$u4ft(v@9ex*=0*w1l*=0v0ixdrey)mmcd2uf#(x'

DEBUG调试:

DEBUG = True

不要在实际生产中打开debug

允许访问的主机:

ALLOWED_HOSTS = ['*']

*是代表允许所有主机访...

Read article

PYTHON August 19, 2018

django查询结果转json的几种方法

Words count 3.7k Reading time 3 mins.

def json_test(request):
    data = {}
    book = Book.objects.all()
    data['list'] = json.loads(serializers.serialize("json", book))
    return JsonResponse(data)

得到的结果:

{
  "list": [
    {
      "pk": 3,
      "model&...
Read article

PYTHON August 19, 2018

django模板组件化

Words count 1.9k Reading time 2 mins.

Django中也有模板组件化的思想。在模板的应用中有包含、继承的概念。

不难理解,包含就是指一个模板里包含另一模板里内容

举个栗子

比如我们要再A.html里应用B.html里的内容,也就是A里包含B,我们可以这样写:

<!DOCTYPE html>
<html>
<head>
    <title>title</title>
</head>
<body> 
{% include 'B.html' %}...
Read article

PYTHON August 19, 2018

Django登录权限控制实现

Words count 4.3k Reading time 4 mins.

django版本:

>>> import django
>>> print django.VERSION
(1, 8, 14, 'final', 0)

python版本:

[root@new_name ~]# python -V
Python 2.7.5

设置中间件

MIDDLEWARE_CLASSES = (
    'django.contrib.sessions.middleware.SessionMiddleware'...
Read article

PYTHON August 19, 2018

django分页查询

Words count 6.2k Reading time 6 mins.

在view.py里添加分页查询方法

from django.http import JsonResponse
from django.views.decorators.http import require_http_methods
from django.core import serializers
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
import json

# 分页查询
def show_page...
Read article

VUE August 19, 2018

ElementUI之button

Words count 2.9k Reading time 3 mins.

        <el-button type="primary">primary</el-button>
        <el-button type="success">success</el-button>
        <el-button type="warning">warning</el-button>
        <el-button type="danger">danger...
Read article

JAVA August 19, 2018

练习1:文件操作和目录遍历

Words count 2.7k Reading time 2 mins.

String getName() //得到一个文件的名称(不包括路径)

String getPath() //得到一个文件的路径名

String getAbsolutePath() //得到一个文件的绝对路径名

String getParent() //得到一个文件的上一级路径名

String renameTo(File newname)
//将当前文件名更名为给定文件的完整路径

boolean exists() //判断指定的文件或目录是否存在

boolean mkdir() //创建文件对象...

Read article

JAVA August 19, 2018

练习4:字符流的写入FileWriter

Words count 892 Reading time 1 mins.

实例:

package com.inspur.io;

import java.io.FileWriter;

/**
 * Created by shirukai on 2017/7/26.
 *
 */
public class Filewrite {
    public static void main(String[] args){
        Filewrite filewrite = new Filewrite();
        filewrite.fileWrite();
    }
    public void...
Read article

JAVA August 19, 2018

练习5:字符流的读取 FileReader

Words count 1.1k Reading time 1 mins.

实例:

package com.inspur.io;

import java.io.File;
import java.io.FileReader;

/**
 * Created by shirukai on 2017/7/26.
 *
 */
public class Filereader {
    public static void main(String[] agrs){
        Filereader filereader = new Filereader();
        filereader.fileReader...
Read article
Load more
0%