Narrow this down and you should be able to work through it. First - is the view getting invoking correctly, regardless of what newforms is doing? If you're running on a dev server instance (i.e. django-admin runserver), then try printing out the request.POST or request.GET in the view to see what is coming through.
You can also invoke django-admin shell and load up the Form and "poke at it", which I've found to be a pretty good debugging tool. i.e. >>> import forms >>> >>> example_data = { 'name' : 'test', 'description' : 'blue', 'vendor' : 'ford' } >>> f = forms.AddTypeForm(example_data) >>> f.is_valid() True or whatever. Break it down into steps to debug it, and then determine if each piece is working. You'll make good progress that way. -joe On 10/2/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > can somebody help me out of newform,i spend one whole day to study > djangosnipppets.com's newform, but it did not work for me. > > models.py: > class Vendor(models.Model): > > name = models.CharField(maxlength=100) > slug = models.SlugField() > > class Type(models.Model): > > vendor = models.ForeignKey(Vendor) > name = models.CharField(maxlength=100) > description = models.TextField() > > forms.py: > from django import newforms as forms > from models import Vendor > > attrs_dict = { 'class': 'required' } > > class AddTypeForm(forms.Form): > def __init__(self, *args, **kwargs): > super(AddTypeForm, self).__init__(*args, **kwargs) > self.fields['language'].choices = [('', '----------')] + > [(x.id, x.name) for x in Vendor.objects.all()] > > > name = forms.CharField(max_length=100, > widget=forms.TextInput(attrs=attrs_dict)) > description = > forms.CharField(widget=forms.Textarea(attrs=attrs_dict)) > vendor = forms.ChoiceField(choices=(), > widget=forms.Select(attrs=attrs_dict)) > > views.py: > def add_car(request): > > if request.method == 'POST': > form = forms.AddTypeForm(request.POST) > if form.is_valid(): > new_type = Type(name=form.clean_data['name'], > > description=form.clean_data['description'], > > vendor_id=form.clean_data['vendor'], > ) > new_type.save() > return HttpResponseRedirect(new_type.get_absolute_url()) > else: > form = forms.AddTypeForm() > return render_to_response('rate/add_car_form.html', > { 'form': form }, > > context_instance=RequestContext(request)) > add_car = login_required(add_car) > > templates: > ........ > > > and i got this error: > > Page not found (404) > Request Method: GET > Request URL: http://127.0.0.1/cars/add/ > > No Vendor matches the given query. > > > > can somebody help me, thanks!!!!! > > > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---