title: Check if a parameter exists in Django URL
body: <p>I am trying to get a URL if it exists in the URL but keep getting the following error:</p>
  <blockquote>
  <p>django.utils.datastructures.MultiValueDictKeyError: 'sc'</p>
  </blockquote>
  <p>The case is that the urls can be sometimes like the following:</p>
  <pre><code>/allot-graph/
  </code></pre>
  <p>and sometimes:</p>
  <pre><code>/allot-graph/?sc='foo'
  </code></pre>
  <p>and in my function I am doing this:</p>
  <pre><code>class AllotmentbyMonth(APIView):
  
      def get(self, request):
  
          q = request.GET['sc']
  
          if q:
  
              print(&quot;q&quot;, q)
  
              dataset = some query
          else:
  
              dataset = some query
  </code></pre>