1

I just started learning Django and Python a few weeks ago and have been tasked with a project to manage form processing using a Django/Python/MySQL combination. My background is in C++, so if there are any C++ analogies in Python/Django syntax please feel free to reference them.

So far I understand what the HTTPRequest objects do, but can't understand this snippet of code:

@login_required(login_url="/some_directory/") def xyz(request): item1 = request.GET['item1'] user = request.user page = Page.objects.get(title = item1) item1info = {} perm_all = get_perms(user,page) item1info["industry"] = page.industry.split(',') 

For the first line what does "@" do? Is "@login_required" a Django command or was was it defined by the coder already?

I know "def xyz(request)" defines a function, but is the parameter "request" something that's been pre-defined in another file (urls.py)?

What does request.GET['item1'] do? Is it retrieving the value of the element "item1" from the query string?

1
  • @login_required is a decorator. Decorators are a fundamental concept in python. I would suggest you read a python tutorial/book before trying to understand django. Commented Feb 20, 2014 at 19:34

1 Answer 1

4
  • "@" is a Decorator. Login required is a decorator provided by Django that requires the current user (in request.user) to be logged in to visit this view.

  • The "request" parameter is passed to the View function when its called, by Django itself. Any valid view function must receive the request as a paramete

  • Request.GET is a python dictionary that contains all the parameters passed in the request by GET method (as part of the URL querystring).

Sign up to request clarification or add additional context in comments.

2 Comments

Where is the view function located? Is it in urls.py?
View functions are located on your app's directory, views.py. Example: myapp/views.py

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.