Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7750259
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T11:14:39+00:00 2026-06-01T11:14:39+00:00

i’m moving my first steps into Django and i’m tryin’ to follow the tutorial

  • 0

i’m moving my first steps into Django and i’m tryin’ to follow the tutorial at this link: https://docs.djangoproject.com/en/dev/topics/forms/modelforms/
but i can’t get a form. It just returns a white page!

Can someone explain if i’m missing something?

my models.py:

from django.db import models
from django.forms import ModelForm

class UserProfile(models.Model):
    name = models.CharField(max_length=30)
    surname = models.CharField(max_length=30)
    email = models.EmailField()
    tel = models.CharField(max_length=30, null=True, blank=True)
    def __unicode__(self):
        return '%s %s' % (self.surname, self.name)

class Ad(models.Model):
    title = models.CharField(max_length=50)
    descr = models.TextField()
    city = models.CharField(max_length=30)
    price = models.FloatField(null=True, blank=True)
    img = models.ImageField(upload_to='./uploaded_imgs', null=True, blank=True)
    dateIn = models.DateField(auto_now_add=True)
    dateExp = models.DateField(auto_now_add=True)
    codC = models.ForeignKey('Cat')
    codU = models.ForeignKey('UserProfile')
    def __unicode__(self):
        return '%s - %s' % (self.title, self.dateIn)

class Cat(models.Model):
    cat = models.CharField(max_length=35, primary_key=True)
    def __unicode__(self):
        return self.cat

my forms.py:

from django import forms

class newAdForm(forms.Form):
    title = forms.CharField(max_length=50)
    descr = forms.CharField(widget=forms.Textarea)
    city = forms.CharField(max_length=30)
    price = forms.FloatField(required=False)
    img = forms.ImageField(required=False)
    dateIn = forms.DateField(auto_now_add=True)
    dateExp = forms.DateField(auto_now_add=True)
    codC = forms.ModelChoiceField(Cat)
    codU = forms.ModelChoiceField(UserProfile)

my views.py:

from django.contrib.auth import authenticate, login, logout
from django.contrib.auth.models import User
from django.shortcuts import render_to_response, get_object_or_404, redirect
from django.template import RequestContext
from django.http import HttpResponse
from django import forms
from models import *
from django.forms import *
from django.forms.models import modelformset_factory

[...]

def newAd(request):
    newAdFormSet = modelformset_factory(Ad)
    if request.method == 'POST':
        formset = newAdFormSet(request.POST, request.FILES)
        if formset.is_valid():
            formset.save()
            return render_to_response('conf.html', {'state':'Your ad has been successfull created.'}, context_instance = RequestContext(request),)
    else:
        formset = newAdFormSet()
    return render_to_response('ad_form.html', context_instance = RequestContext(request),)

my ad_form_auto.html template:

{% extends "base.html" %}
{% block title %}Ads insertion form{% endblock %}
{% block content %}
    {% if error_message %}
        <p><strong>{{ error_message }}</strong></p>
    {% endif %}
<form method="post" action="">
    {{ formset }}
</form>
{% endblock %}

Thanks a lot! This community looks just awesome! 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T11:14:41+00:00Added an answer on June 1, 2026 at 11:14 am

    You’re not passing the form to the template – at present your ‘formset’ variable containing the form isn’t included in the datadict being passed to the view.

    return render_to_response('ad_form.html', context_instance = RequestContext(request),)
    

    Should include the data (see render_to_response() docs) here I’ve renamed the form in your data and to your template as ‘form’ for ease of nomenclature:

    return render_to_response('ad_form.html',
                              {'form':formset},
                              context_instance=RequestContext(request))
    

    Then, in your template (see forms in templates docs) replace {{formset}} with {{form.as_p}}. Also add a submit button to the form.

    <form action="" method="post">
        {% csrf_token %}
        {{ form.as_p }}
        <input type="submit" value="Submit" />
    </form>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
For some reason, after submitting a string like this Jack’s Spindle from a text
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into
We're building an app, our first using Rails 3, and we're having to build
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
Does anyone know how can I replace this 2 symbol below from the string

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.