Skip to content

Instantly share code, notes, and snippets.

@githubutilities
Last active November 13, 2015 11:59
Show Gist options
  • Select an option

  • Save githubutilities/43fc1b7d2f4ca0765154 to your computer and use it in GitHub Desktop.

Select an option

Save githubutilities/43fc1b7d2f4ca0765154 to your computer and use it in GitHub Desktop.
Django Framework Code Management

Django Framework Code Management

  1. Form. django.forms.Form
  2. View(controller in MVC sense, actually Django is a MTV(Model Template View) Framework.) process the Form with data within Model and feed Template with dictionary or response with a JsonResponse.
  3. Model. django.db.models.Model
  4. Template. Supplied with dictionary by View.

Form

if request.method == 'POST':
    form = CustomForm(request.POST, request.FILES)
    if form.is_valid():
        rank = form.cleaned_data['rank']
        image = request.FILES['image']

        return HttpResponseRedirect('/')

Template

return render_to_response(
    'templates.html',
    {'data': data},
    context_instance=Context(request),
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment