You will get a clearer image of the process by understanding it with an example. Read: Python Django vs Flask. In this section, I will be using my localhost address for the demonstration purpose. I have created a path to the products endpoint. I have defined the path converter as int to specify that the URL parameter will be an integer. Do not get confused with the path named index.
It is just a path pointing to my base URL. The views. The above function will receive the parameter from the request. I have passed this parameter to a Django template named result. This Django template will be rendered when the request is made. Now let us have a look at the output:. You can see that the parameter value passed to the URL is shown in the Django template.
If I change the value of the parameter, the result will also change:. Thus, you might have got a basic understanding of passing the parameters in a URL in Django. I will explain more examples in the upcoming sections. But before that let us learn about the path converters in Django. Read: Python Django get admin password.
Path converters in Django specify what type of data you are trying to send as parameters through URL. In the above example, I used the int path converter to pass integer values as the URL parameter. However, you can also use other in-built path converters.
Below are some in-built path converters that you can use while defining the URL parameters:. For example, passing a product id. For example, passing a username or token. You might have seen a slug parameter in blogs or articles websites. In this URL, python-django-get is the slug parameter.
You can use this path converter if you want to pass a UUID as the parameter. Example 1: Python. A Simple Python template example. Create a template that has placeholder for value of x. Substitute value of x in above template. A Python program to demonstrate the. List Student stores the name and marks of three students. We are creating a basic structure to print the name and. Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
Next Python String. Recommended Articles. Article Contributed By :. No, I just try to auto generate serializer file for django rest framework with some options — mng back. Add a comment. Active Oldest Votes. Library register. MojixCoder MojixCoder 1, 5 5 silver badges 15 15 bronze badges. I think you misunderstand me the id,name is just a string all I need is to add double quotes to them to be like that "id","name" — mng back.
The problem that id,name is in one variable not seprated so it's like that I have a variable called fields which equal to id,name — mng back. Hussain Pettiwala Hussain Pettiwala 4 4 silver badges 14 14 bronze badges. Sign up or log in Sign up using Google. Sign up using Facebook. Sign up using Email and Password. Post as a guest Name.
0コメント