推广管理系统开发过程总结

it不难
2022-09-03 / 0 评论 / 11 阅读 / 正在检测是否收录...

前言

设计思路

photo模块

模型设计

后台展示自定义

新增订单接口

def photo_add(request):
    #定义返回字典
    resp = {}
    #获取请求参数
    if request.method == 'GET':
        u = request.GET.get('u', default=False)
        n =  request.GET.get('n', default='xwzy1130')
    else:
        u  = False

    if not u:
        resp['msg'] = '参数非法,提交失败!'
    else:
        data = get_info_by_url(u)
        if data:
            art = Article()
            art.sno = datetime.now().strftime('%Y%m%d%H%M%S') + ''.join(str(i) for i in random.sample(range(0,9),4))
            art.title = data[0]
            art.url = u
            art.stype = data[1]
            payinfo = PayInfo.objects.filter(username=n).last()
            if payinfo:
                art.uid = payinfo.uid
            else:
                art.uid = 1
                art.note = n
            art.save()
            resp['msg'] = '更新成功!查询码:{}'.format(art.sno)
        else:
            resp['msg'] = '提交失败!'
    return JsonResponse(resp)

frontend模块

view模版

#搜索结果页
def search_view(request,*args, **kwargs):
    return  render(request, 'frontend/search.html')

#自助提交页
def submit_view(request,*args, **kwargs):
    return  render(request, 'frontend/submit.html')

submit.html

 $(function () {
        // 搜索时执行ajax 查询匹配的数据 返回到list
        $(".handIpt").click(function () {
            var username = $("#username").val();
            var url = $("#url").val();
            if (isValidURL(url) && url.trim()) {
                $.ajax({
                    type: "GET",
                    url: "/photo/add?u=" + url + "&n=" + username,
                    dataType: "json",
                    success: function (data) {
                        alert(data.msg);
                    },
                    //打印错误
                    error:function(jqXHR,textStatus,errorThrown){
                        console.log(jqXHR);
                        console.log(textStatus);
                        console.log(errorThrown);
                    }
                });
            } else {
                alert("请检查推广链接!");
            }
        });

其他细节

js校验url是否合法

  function isValidURL(str_url) {
        var strRegex = "^((https|http|ftp|rtsp|mms)?://)"
  + "?(([0-9a-z_!~*'().&=+$%-]+: )?[0-9a-z_!~*'().&=+$%-]+@)?" //ftp的user@
        + "(([0-9]{1,3}.){3}[0-9]{1,3}" // IP形式的URL- 199.194.52.184
        + "|" // 允许IP和DOMAIN(域名)
        + "([0-9a-z_!~*'()-]+.)*" // 域名- www.
        + "([0-9a-z][0-9a-z-]{0,61})?[0-9a-z]." // 二级域名
        + "[a-z]{2,6})" // first level domain- .com or .museum
        + "(:[0-9]{1,4})?" // 端口- :80
        + "((/?)|" // a slash isn't required if there is no file name
        + "(/[0-9a-z_!~*'().;?:@&=+$,%#-]+)+/?)$";
        var re=new RegExp(strRegex);
        //re.test()
        if (re.test(str_url)){
            return (true);
        }else{
            return (false);
        }
    }

js 转码url

 // var e_url = encodeURIComponent (list[i].url);
 function movieDetail (url) {
        console.log(url);
        window.location.href= decodeURIComponent(url);
    }

Django设置静态文件目录

STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'collect_static')

STATICFILES_DIRS = [
    os.path.join(BASE_DIR, 'static')
]

simpleUI 设置默认首页

#simpleui配置
SIMPLEUI_HOME_PAGE = '/photo/index'
0

评论 (0)

取消