Skip to content

Commit 60369bc

Browse files
committed
add web and cv search demo.
1 parent ee8be68 commit 60369bc

57 files changed

Lines changed: 846 additions & 0 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

24web/django_demo/HelloWorld/HelloWorld/__init__.py

Whitespace-only changes.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# -*- coding: utf-8 -*-
2+
"""
3+
@author:XuMing([email protected])
4+
@description:
5+
"""
6+
7+
from django.http import HttpResponse
8+
from django.shortcuts import render
9+
10+
11+
# 表单
12+
def search_form(request):
13+
return render(request,'search_form.html')
14+
15+
16+
# 接收请求数据
17+
def search(request):
18+
request.encoding = 'utf-8'
19+
if 'q' in request.GET and request.GET['q']:
20+
message = '你搜索的内容为: ' + request.GET['q']
21+
else:
22+
message = '你提交了空表单'
23+
return HttpResponse(message)
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# -*- coding: utf-8 -*-
2+
"""
3+
@author:XuMing([email protected])
4+
@description:
5+
"""
6+
7+
from django.shortcuts import render
8+
from django.views.decorators import csrf
9+
10+
11+
# 接收POST请求数据
12+
def search_post(request):
13+
ctx = {}
14+
if request.POST:
15+
ctx['rlt'] = request.POST['q']
16+
return render(request, "post.html", ctx)
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
# -*- coding: UTF-8 -*-
2+
"""
3+
Django settings for HelloWorld project.
4+
5+
Generated by 'django-admin startproject' using Django 2.0.
6+
7+
For more information on this file, see
8+
https://docs.djangoproject.com/en/2.0/topics/settings/
9+
10+
For the full list of settings and their values, see
11+
https://docs.djangoproject.com/en/2.0/ref/settings/
12+
"""
13+
14+
import os
15+
16+
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
17+
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
18+
19+
# Quick-start development settings - unsuitable for production
20+
# See https://docs.djangoproject.com/en/2.0/howto/deployment/checklist/
21+
22+
# SECURITY WARNING: keep the secret key used in production secret!
23+
SECRET_KEY = 'ekjfodu5w(jy+vk(yku_h0%!@3=lx=f5aqre-3@hnmmjm1%nuw'
24+
25+
# SECURITY WARNING: don't run with debug turned on in production!
26+
DEBUG = True
27+
28+
ALLOWED_HOSTS = ["0.0.0.0","127.0.0.1"]
29+
30+
# Application definition
31+
32+
INSTALLED_APPS = [
33+
'django.contrib.admin',
34+
'django.contrib.auth',
35+
'django.contrib.contenttypes',
36+
'django.contrib.sessions',
37+
'django.contrib.messages',
38+
'django.contrib.staticfiles',
39+
'TestModel',
40+
]
41+
42+
MIDDLEWARE = [
43+
'django.middleware.security.SecurityMiddleware',
44+
'django.contrib.sessions.middleware.SessionMiddleware',
45+
'django.middleware.common.CommonMiddleware',
46+
'django.middleware.csrf.CsrfViewMiddleware',
47+
'django.contrib.auth.middleware.AuthenticationMiddleware',
48+
'django.contrib.messages.middleware.MessageMiddleware',
49+
'django.middleware.clickjacking.XFrameOptionsMiddleware',
50+
]
51+
52+
ROOT_URLCONF = 'HelloWorld.urls'
53+
54+
TEMPLATES = [
55+
{
56+
'BACKEND': 'django.template.backends.django.DjangoTemplates',
57+
'DIRS': [BASE_DIR + "/templates"],
58+
'APP_DIRS': True,
59+
'OPTIONS': {
60+
'context_processors': [
61+
'django.template.context_processors.debug',
62+
'django.template.context_processors.request',
63+
'django.contrib.auth.context_processors.auth',
64+
'django.contrib.messages.context_processors.messages',
65+
],
66+
},
67+
},
68+
]
69+
70+
WSGI_APPLICATION = 'HelloWorld.wsgi.application'
71+
72+
# Database
73+
# https://docs.djangoproject.com/en/2.0/ref/settings/#databases
74+
75+
DATABASES = {
76+
'default': {
77+
'ENGINE': 'django.db.backends.mysql',
78+
'NAME': 'fc_show_risk',
79+
'USER': 'root',
80+
'PASSWORD': 'lucy123456',
81+
'HOST': '10.194.246.12',
82+
'PORT': '8100',
83+
}
84+
}
85+
86+
# Password validation
87+
# https://docs.djangoproject.com/en/2.0/ref/settings/#auth-password-validators
88+
89+
AUTH_PASSWORD_VALIDATORS = [
90+
{
91+
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
92+
},
93+
{
94+
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
95+
},
96+
{
97+
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
98+
},
99+
{
100+
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
101+
},
102+
]
103+
104+
# Internationalization
105+
# https://docs.djangoproject.com/en/2.0/topics/i18n/
106+
107+
LANGUAGE_CODE = 'en-us'
108+
109+
TIME_ZONE = 'UTC'
110+
111+
USE_I18N = True
112+
113+
USE_L10N = True
114+
115+
USE_TZ = True
116+
117+
# Static files (CSS, JavaScript, Images)
118+
# https://docs.djangoproject.com/en/2.0/howto/static-files/
119+
120+
STATIC_URL = '/static/'
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# -*- coding: utf-8 -*-
2+
"""
3+
@author:XuMing([email protected])
4+
@description:
5+
"""
6+
7+
# -*- coding: utf-8 -*-
8+
9+
from django.http import HttpResponse
10+
11+
from TestModel.models import RiskData
12+
13+
14+
# 数据库操作
15+
def testdb(request):
16+
test1 = RiskData(title='runoob')
17+
test1.save()
18+
return HttpResponse("<p>数据添加成功!</p>")
19+
20+
21+
# 数据库操作
22+
def show_db(request):
23+
# 初始化
24+
response = ""
25+
response1 = ""
26+
27+
# 通过objects这个模型管理器的all()获得所有数据行,相当于SQL中的SELECT * FROM
28+
list = RiskData.objects.all()
29+
30+
# filter相当于SQL中的WHERE,可设置条件过滤结果
31+
response2 = RiskData.objects.filter(id=1)
32+
33+
# 获取单个对象
34+
response3 = RiskData.objects.get(id=1)
35+
36+
# 限制返回的数据 相当于 SQL 中的 OFFSET 0 LIMIT 2;
37+
RiskData.objects.order_by('userid')[0:2]
38+
39+
# 数据排序
40+
RiskData.objects.order_by("id")
41+
42+
# 上面的方法可以连锁使用
43+
RiskData.objects.filter(title="runoob").order_by("id")
44+
45+
# 输出所有数据
46+
for var in list:
47+
response1 += var.title + " " + var.show_url
48+
response = response1
49+
return HttpResponse("<p>" + response + "</p>")
50+
51+
52+
# 数据库操作
53+
def update_db(request):
54+
# 修改其中一个id=1的name字段,再save,相当于SQL中的UPDATE
55+
test1 = RiskData.objects.get(id=1)
56+
test1.name = 'Google'
57+
test1.save()
58+
59+
# 另外一种方式
60+
# Test.objects.filter(id=1).update(name='Google')
61+
62+
# 修改所有的列
63+
# Test.objects.all().update(name='Google')
64+
65+
return HttpResponse("<p>修改成功</p>")
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
"""HelloWorld URL Configuration
2+
3+
The `urlpatterns` list routes URLs to views. For more information please see:
4+
https://docs.djangoproject.com/en/2.0/topics/http/urls/
5+
Examples:
6+
Function views
7+
1. Add an import: from my_app import views
8+
2. Add a URL to urlpatterns: path('', views.home, name='home')
9+
Class-based views
10+
1. Add an import: from other_app.views import Home
11+
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
12+
Including another URLconf
13+
1. Import the include() function: from django.urls import include, path
14+
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
15+
"""
16+
from django.conf.urls import url
17+
from django.urls import re_path
18+
from django.contrib import admin
19+
20+
from . import view, testdb, search, search_post
21+
22+
urlpatterns = [
23+
url(r'^$', view.hello),
24+
url('hello/', view.hello),
25+
re_path(r'^index/$', view.index, name='index'),
26+
url(r'^testdb$', testdb.testdb),
27+
re_path('showdb/', testdb.show_db),
28+
re_path('update_db/', testdb.update_db),
29+
url(r'^search-form$', search.search_form),
30+
url(r'^search$', search.search),
31+
re_path(r'^search-post$', search_post.search_post),
32+
url(r'^admin/', admin.site.urls),
33+
34+
]
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# -*- coding: utf-8 -*-
2+
"""
3+
@author:XuMing([email protected])
4+
@description:
5+
"""
6+
from django.http import HttpResponse
7+
from django.shortcuts import render
8+
9+
10+
def hello(request):
11+
context = {}
12+
context["hello"] = 'helloo1 world'
13+
context["say"] = 'say world'
14+
persons = [{'name': 'lILli', 'score': 30}, {'name': 'lucy', 'score': 50}, {'name': 'tom', 'score': 80}, ]
15+
context['persons'] = persons
16+
return render(request, 'hello.html', context)
17+
18+
19+
def index(request):
20+
return HttpResponse("Hello world ! ")
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
"""
2+
WSGI config for HelloWorld project.
3+
4+
It exposes the WSGI callable as a module-level variable named ``application``.
5+
6+
For more information on this file, see
7+
https://docs.djangoproject.com/en/2.0/howto/deployment/wsgi/
8+
"""
9+
10+
import os
11+
12+
from django.core.wsgi import get_wsgi_application
13+
14+
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "HelloWorld.settings")
15+
16+
application = get_wsgi_application()

24web/django_demo/HelloWorld/TestModel/__init__.py

Whitespace-only changes.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from django.contrib import admin
2+
3+
# Register your models here.
4+
from TestModel.models import RiskData,Contact, Tag
5+
6+
admin.site.register(RiskData)
7+
admin.site.register(Tag)
8+
admin.site.register(Contact)

0 commit comments

Comments
 (0)