在基于函数的视图中获取URL参数

时间:2019-05-03 07:02:32

标签: django django-views

我想在基于函数的视图中添加URL参数怎么办?

http://127.0.0.1:8000/xxxxx/4

参数为4我想将A设为4。有什么办法吗?

3 个答案:

答案 0 :(得分:2)

import pandas as pd data = {'ID': ["a1","a2","a3","a4","a5","a6","a7","a8","a9","a10","a11","a12","a13","a14","a15","a16","a17","a18","a19","a20","a21","a22"], 'Unit_Weight': [178,153,193,195,214,157,205,212,219,166,217,186,170,207,204,201,179,215,213,170,217,199]} df = pd.DataFrame(data) size = 6 # 6 rows in a new data-frame list_of_dfs = [df.loc[i:i+size-1,:] for i in range(0, len(df),size-2) if i <len(df)-2] for l_d in list_of_dfs: print (l_d)

Function-Based Views:

def Homepage(request, pk):

In class-based views

答案 1 :(得分:1)

您正在寻找tutorial

您的示例解决方案如下。

urls.py

from django.urls import path

from . import views

urlpatterns = [
    path('xxxx/<int:your_number>/', views.your_view_name),
]

views.py

def your_view_name(request, your_number):
    # do things with your_number here.
    # if your_number is optional, define a default
    return render(...)

答案 2 :(得分:0)

self.kwargs['blog_ID']

def blogpost(request,blog_ID):