당신이 당신의 URL을 조정 괜찮다면 조금 직접 URL로 필터 옵션을 포함 할 수 있습니다. 실제로 검색 옵션을 북마크 할 수있는 아주 좋은 부수적 이점이 있습니다. 따라서 사용자가 페이지 매김의 다음/이전 버튼을 클릭하면 모든 정보가 URL에서 전달됩니다.
그 페이지의 URL을 조금씩 분할해야 할 수도 있습니다. 뷰 함수에 몇 가지 키워드 args를 사용했다면, 그 뷰에 대한 모든 로직을 한 함수에 넣을 수 있습니다. 당신의 view.py에서
urlpatterns = patterns('',
(r'^some_url/to/form/$', 'myapp.myview'),
(r'^some_url/to/form/(?P<filter>[^/]+)/$', 'myapp.myview'),
)
다음 urls.py에서
빠른 예를
def myview(request, filter=None):
if request.method == 'POST':
# if the form is valid then redirect the user to the URL
# with the filter args embedded
elif filter is None:
form = MyForm() # init it with the blank defaults
elif filter is not None:
# Convert your filter args to a dict
data = {'my_form_field' : filter}
form = MyForm(data)
else:
# Sanity checking just in case I missed a case. Raise an exception.
# the rest of the display logic for the initialized form
이 같은 솔루션이 적용되지 않습니다 사용하는 경우는, 확실히 있습니다 만 당신의 구체적인 사건에 대해 더 많이 알지 못해서 나는 말할 수 없습니다.
희망이 도움이됩니다.
사실, 결국 나는 매우 우아하지는 않았지만 링크로 필터를 하드 코딩했습니다. – alj