股票代码查询页面
首先看页面
引子
源于运营组同事和运维组同事的一点交互工作,运营同事经常会有配售、申购股票代码查询的动作,而这个生产查询的接口只有运维同事有权限,所以此页面的主要目的是打通生产到办公网数据传输,交由运营同事自助查询。
本例是一个最基本最简单的Django案例
软件版本介绍
- OS RHEL6.5
- Python 2.6.6
- Django 1.6.8
Django框架
views.py
# _*_ encoding=utf-8 _*_ __author__ = 'weizhen' from django.shortcuts import render_to_response import time import sys import re import os reload(sys) sys.setdefaultencoding('utf8') base_dir = os.path.dirname(os.path.abspath(__file__)) def index(request): ret = {'result':''} result = '' today = time.strftime('%Y%m%d', time.localtime()) codelist_file = '%s/%s.txt'%(basedir,today) f = open(codelist_file,'r') if request.method == 'POST': inp_codenum = request.POST.get('codenum', None) result = '%s 无干扰K线'%inp_codenum k_day_1 = '%s.day' % inp_codenum k_day_2 = '%s.Day' % inp_codenum k_day_1 = str(k_day_1) k_day_2 = str(k_day_1) for i in f: line = re.split(' ',i)[-1].strip('\n') if k_day_1 == line or k_day_2 == line: result = '%s 存在干扰K线,请邮件运维进行盘后处理'%inp_codenum break f.close() ret['result'] = result return render_to_response('selfcheck/index.html',ret)
selfcheck/index.html
<!DOCTYPE html> <html lang="en"> <head class="ui semantic"> <meta charset="UTF-8"> <!-- <meta name="viewport" content="width=device-width, initial-scale=1.0"> --> <!-- //<meta http-equiv="X-UA-Compatible" content="ie=edge"> --> <title>查询</title> <script src="/static/js/jquery-2.1.4.min.js"></script> <script src="/static/js/semantic.min.js"></script> <link rel="stylesheet" type="text/css" href="/static/css/semantic.min.css"> <style> .topheader>a { padding-right: 15px; color: black; background-color: #fff; /* text-decoration:underline; */ font-weight: bold; } a { text-decoration: underline; color: rgba(109, 99, 99, 0.76); font-size: 5px; } .bri { display: inline-block; right: 10px; width: 60px; height: 23px; color: #fff; background: #38f; line-height: 24px; font-size: 13px; text-align: center; overflow: hidden; /*border-bottom: 1px solid #38f;*/ margin-left: 19px; margin-right: 2px; } </style> </head> <body> </br> </br> </br> </br> <div class="ui centered aligned grid container "> <div class="column" style="width: 270px;height: 129px;"> <h2><font color="red">沪深市场重复代码查询</font></h2> </div> <div class="row"> <form class="column" style="width:640px;" method="POST"> <div class="ui fluid input action"> <input type="text" name="codenum" placeholder="搜索股票代码..."> <button class="medium ui blue button" onclick="document.forms['search'].submit();">搜索一下</button> </div> </form> </div> <div class="row"> <form class="column" style="width:640px;"> <div class="ui fluid input action"> <font color="red"><b>{{ result }}</b></font> </div> </form> </div> </div> </body> </html>
附关于静态页面配置方法
STATIC_URL = '/static/' STATICFILES_DIRS = ( os.path.join(BASE_DIR,'static') ) STATICFILES_DIRS = ( BASE_DIR + '/static', )