如何访问"参数"网址中的字词:
operations_product_search/?q=parameter
这里:
类ASearchView(ListView):
...
def get_queryset(self, **kwargs):
q = self.kwargs["q"] <--- This is not working
答案 0 :(得分:5)
应该是self.request.GET['q']
。
答案 1 :(得分:1)
我使用query_params
获取查询参数public class GluonApplication extends MobileApplication {
@Override
public void init() {
addViewFactory(HOME_VIEW, () ->
{
TextField txtFloating = new TextField();
txtFloating.setFloatText("floating");
TextField txtNonFloating = new TextField();
txtNonFloating.setPromptText("non floating");
Button btnClear = new Button("clear text");
btnClear.setOnAction(e -> {
txtFloating.setText(null);
txtNonFloating.setText(null);
});
VBox boxContent = new VBox(20,txtNonFloating, txtFloating, btnClear);
boxContent.setAlignment(Pos.CENTER);
View view = new View(boxContent) {
@Override
protected void updateAppBar(AppBar appBar) {
appBar.setTitleText("Home");
}
};
return view;
});
}
答案 2 :(得分:1)
如果您使用get()
,则可以通过提供备用值(此处为None
)来避免URL中不存在'q ='的异常:
def get_queryset(self):
q = self.request.GET.get('q', None)