Django view variables based on url -


I am starting with a dragon, so bear with me

We say that My model is:

  class event (model.model): name = model.carfild (max_length = 100, verbose_name = _ ('name')) location = model.carfield (max_length = 200 , verbose_name = _ ('location')) start_time = models.DateTimeField (verbose_name = _ ('start time')) end_time = models.DateTimeField (verbose_name = _ ('end time')) sales_start = models.DateField (verbose_name = _ ('Start sale')) sales_end = models.DateField (verbose_name = _ ('sale end')) event_active = models.BooleanField (verbose_name = _ (' Event active ')) Price = models.IntegerField (verbose_name = _ (' price ')) max = models.IntegerField (verbose_name = _ (' max ')) = information model =. Kharefild (max_length = 500, verbose_name = _ ('information')) Logo = model. ImageField (verbos_name = _ ('logo'), empty = true, upload_to = 'img /% y /% m /% d')   

What I would like to accomplish is to create a single page And fill it with 'data' from the data, I want to get this event by getting the ID from the URL.

I am sure how to do this because I do not understand parts of the documentation because I am not a native English speaker.

"itemprop =" text ">

I think this is what you are trying to do:

 # Urls.py # 'event_id' will be passed to the URL '? R'events / (P & LT; event_id & gt; \ d +) / $', 'as the argument for the' Show_event 'view, show_event ', name =' show_event ') # views.py Def show_event (request, event_id): ... # This will return a 404 response event with event id is not found event = get_object_or_404 (event, id = Event_id) ... return render (request, 'template.html', {'incident': event}) # template .html & lt; H1 & gt; Welcome to the event {{event.name}} & lt; / H1>   

You will use the URL like this: yourdomain.com/events/123 . This is the reason that will drag the event id from the URL 123 and template.html , to send the appropriate incident item in the template context so that you can provide it as you Want to

Comments

Popular posts from this blog

Pass DB Connection parameters to a Kettle a.k.a PDI table Input step dynamically from Excel -

multithreading - PhantomJS-Node in a for Loop -

c++ - MATLAB .m file to .mex file using Matlab Compiler -