[Answered ]-How to define optional query parameters in Django?

1๐Ÿ‘

โœ…

As mentioned in the comments using query-parameter try this

URL

re_path(r'^project_config/',views.results, name='config')

# http://127.0.0.1:8000/project_config/?product=1&project_id=2&project_name=foo

Views

def results(request):
    
    queryprms = request.GET
    product = queryprms.get('product')
    project_id = queryprms.get('project_id')
    project_name = queryprms.get('project_name')
    
    response = "You're looking at the results of question %s."
    
    # set your combination
    if product and project_id and project_name:
        # do some thing
    if product and project_id:
        # do some thing
    
    # so on

    return HttpResponse(response % project_id)
๐Ÿ‘คrahul.m

Leave a comment