Django url带请求参数

  • view.py

请求参数db_name

# 根据order_no查询数据库
def query_db_by_order_no(request, db_name):
    # 获取db
    dbs = DataDb.objects.filter(db_name=db_name)
    cs_list = []
    cs = dbs[0].collection_set.all()
    for c in cs:
        cs_list.append(c.name)
    coll = request.GET.get("collection")
    orderId = request.GET.get("orderId")
    # 连接数据库
    mg = MongoDb()
    # 建立连接
    db = mg.conn[db_name]
    query_db = DataDb.objects.filter(db_name=db_name).values()

    order_sql = {"order_no": orderId}
    if query_db:
        db.authenticate(query_db[0]['user_name'], query_db[0]['password'])
        if coll:
            query_db_by_order = mg.db_find(db, coll, order_sql)
        else:
            query_db_by_order = None

        context = {
            "db_name": db_name,
            "cs_list": cs_list,
            "coll": coll,
            "query_db_by_order": query_db_by_order,
        }
        print(context)
        return render(request, "query/query_order.html", context)
  • urls.py
# query oreder
    path('query//', views.query_db_by_order_no, name='querydb'),
  • html
  • order
  • 你可能感兴趣的:(Django url带请求参数)