django学习
迁移django项目会无法运行,
1.要指定运行的IP
2.python manage.py makemigrations --empty ‘应用名' (数据库重建)
添加favicon.ico图标的方法有两种
首先先制作一个ico文件,使用PS或者某些在线生成ico的网站即可,我是在下面的网站生成的,当然,你也可以用其他网站!
http://tools.jb51.net/aideddesign/ico_img
下载后将此文件命名为“favicon.ico”后放在static/blog/img/下
方法一、在url.py中添加:
from Django.views.generic.base import RedirectView urlpatterns=[ ... # favicon.cio url(r'^favicon\.ico$', RedirectView.as_view(url=r'static/blog/img/favicon.ico')), ]
django下的序列化,不采用drf的方式
1 from django.shortcuts import render,HttpResponse 2 from django.views import View 3 from .models import Student #引入模块 4 from django.core import serializers #django的序列化器 5 # Create your views here. 6 7 class StudentView(View): 8 def get(self,request): 9 student = Student.objects.all() #queryset类型 10 data = serializers.serialize("json",student) 11 print(data) 12 return HttpResponse("ok") 13 def post(self,request): 14 pass
ORM操作
#增加
Public_network_access_authorizat.objects.create(
policy_name=key,
source_zone=public_acc_auth[1].get('source-zone'),
destination_zone=public_acc_auth[1].get('destination-zone'),
)
#删除
address = Public_network_access_authorizat.objects.all()
address.delete()
Public_network_access_authorizat.objects.filter(id=1).deletl(policy_name='xxxxxxxxx')
#修改
Public_network_access_authorizat.objects.filter(id=1).updata()
#查询
1.正向查询
addsess = Address_set.objects.all()
for value in addsess:
public_permit_domain = {}
name = value.public_auth.policy_name #跨表
ip = value.address
source_zone = value.public_auth.source_zone
destination_zone = value.public_auth.destination_zone
public_permit_domain['name'] = name
public_permit_domain['ip'] = ip
public_permit_domain['source_zone'] = source_zone
public_permit_domain['destination_zone'] = destination_zone
2.反向查询
public_obj = Public_network_access_authorizat.objects.get(policy_name='LVS-out')
#注意表名是小写
addset = public_obj.addressgroup_set.all()
for i in addset:
print(i.address)