1

I'm just trying to get a minimum working example of GET variable usage in django. Apologies, I'm very very new to django.

At the moment, urls.py looks like:

urlpatterns = [
    url(r'^admin/', admin.site.urls),
     url(r'^test/', views.engage),
]

views.py:

def engage(request):
  return(request.GET)

I'm trying to access an integer variable at domain.com/test/&n=10 but at this stage I keep getting

Exception Type: AttributeError
Exception Value:    
This QueryDict instance is immutable

I've been trying to figure this out for about 2 days now. I've searched pretty widely, but I just don't seem to be getting anywhere. I don't need the answer on a silver platter; links to tutorials etc would be equally appreciated. I feel like there's something pretty core that I'm missing.

Thanks.

1 Answer 1

2

If engage is a view, it needs to return a response. Preferably an HTTP response that the user's browser can render.

You can try something like this:

def engage(request):
  n = int(request.GET.get('n', 0))
  return HttpResponse('<html><body>You sent over %s</body></html>' % n)

Also your URL should look like:

domain.com/engage/?n=10
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.