Q:

How to pass values to defined template from views.py in Django-python

I have a model like this:
class EventTypeCategory(models. Model):
    name = models. CharField(max_length=50, verbose_name="Name")
    user = models. ForeignKey(User, verbose_name="User")
    Message_slug = models. SlugField(blank=True, verbose_name="Message")

       def __unicode__(self):
           return self.name

In urls.py:
url(r'^categ/$',
    'eventcateg_detail', name='eventcateg_detail'),

In views.py:
def eventcateg_detail(request,event_categ_id=None, event_categ_slug=None):

I want to add/edit/delete(CRUD) above defined value i.e name and Message_slug by template level.  I am not getting any hint how to relate url.py with views.py and what should be definition of eventcateg_detail function. How this function will pass values to template (template name will be categ.html)
I am newbie in Django :)
want your help

A:

You need to allow the URL to accept parameters to allow you specify which event category you want to view:
/categ/outdoor-events/
/categ/catered-events/ 
...

Do do this, you use a named URL pattern in your url scheme:
url(r'^categ/(?P<slug>[-\w]+)/$','eventcateg_detail', name='eventcateg_detail'),

and in your view:
from django.shortcuts import get_object_or_404, render
def eventcateg_detail(request,slug):
    return render(request, "categ.html", {
        'obj' : get_object_or_404(EventCateg, Message_slug =slug) # You should change Message_slug to just slug
    })

and in your template:
<h1>{{ obj.name }}</h1>

So when a user enters a URL like we have outlined above, it gets matched to our URL pattern and the slug part of the url (catered-events) gets passed as a parameter to our view. 