Friday, December 29, 2017

Re: Possible bug Django 2.0 CreateView generic CBV

Hi Steven,

Could you put a "import pdb; pdb.set_trace()" somewhere in your code?

This way it would be pretty easy to inspect where the code is breaking.

Besides, why upgrading to Class-based-views if your previous Django 1.11 implementation was working fine?



Le 2017-12-28 à 20:44, Steven Meyer a écrit :
I hope I've got the right group this time. I originally posted it on Django core membership but Tim Graham emailed me to say it was the wrong group.

I am very new to Django - been at it for five weeks. Not sure whether this is a bug or my own stupidity.

Here is my model in an app called gcbv (for generic class-based view)

from django.db import models
from core.models import TimeStampModel
from django.urls import reverse
# Create your models here.

class Vehicle(TimeStampModel):
maker = models.CharField(max_length=100)
model_year = models.IntegerField()
vehicle_type = models.CharField(max_length=100)
slug = models.SlugField(max_length=100, unique=True)
vehicle_model = models.CharField(max_length=100)
website = models.URLField(max_length=100, blank=True)
email = models.EmailField(max_length=100, blank=True)
notes = models.TextField(blank=True, default='')
def __str__(self):
x = self.maker + ' ' + self.vehicle_model
return x

And here are the URLs

from django.contrib import admin
from django.urls import path, include
from django.conf.urls import url
from . import views
from django.urls import reverse
#from django.views.generic.base import TemplateView

app_name = 'gcbv'

urlpatterns = [
    path('sub1/', views.SubView.as_view(), name='sub1'),
    path('vehicle_list/', views.VehicleListView.as_view(),
        name = 'vehicle_list'),
    path('vehicle/create', views.VehicleCreateView.as_view(),
    path('', views.IndexTemplateView.as_view(), name='index'),

And here is the relevant view

class VehicleCreateView(CreateView):
model = Vehicle
fields = ['maker', 'model_year', 'vehicle_type', 'slug',
    'vehicle_model', 'website', 'email', 'notes']
labels = {'maker':'Maker', 'model_year':'Year', 
    'vehicle_type':'Type', 'vehicle_model':'Model',
    'website':'Website', 'email':'Email', 'notes':'Notes'}

Here is the template:

{% extends "core/base.html" %}
{% block body_block %}
<h1>Vehicle Create for GCBV</h1>

<form action="POST" action="">

  {% csrf_token %}
  {{ form.as_p }}
  <button name="submit" class="btn btn-primary">Submit</button>

<h1>End Vehicle Create for GCBV</h1>
{% endblock %}

I've attached screenshots of:

--The rendered form template

--What happens after I click submit

It looks as if the data is not being saved to the database.

If I add the same data from admin everything works fine. I've attached another screenshot showing that VehicleDetailView has found the relevant template and rendered the information.

Any help would be greatly appreciated.

NB: This all worked fine when I was using function views and regex instead of path.

You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
To post to this group, send email to
Visit this group at
To view this discussion on the web visit
For more options, visit

--   Etienne Robillard

No comments:

Post a Comment