0

Assume all imports done.

I have a model like this:

class Package(models.Model):
  uuid = models.UUIDField(default=uuid.uuid4, editable=False)
  name = models.CharField(max_length=400)

Then I want to use generic ListView like so:

class PackageList(ListView):
  model = Package
  template_name = 'package/list.html'

All with url like so:

url(r'^package/list/$', views.PackageList.as_view(), name='package_list'),

When I visit the localhost:8000, I get ValueError at /package/list/ badly formed hexadecimal UUID string

However, a DetailView generic view loads the detail based on the uuid successfully, without any issues.

The error comes up only when using the ListView.

What am I doing wrong?

KhoPhi
  • 9,660
  • 17
  • 77
  • 128
  • First thing first, your url says `/package/list/`, but in your question you've mentioned `/travel/list/`. Are you sure you're going to the correct url? – kaveh Mar 28 '17 at 22:15
  • @kaveh Fixed them now. Was typo in question – KhoPhi Mar 28 '17 at 22:17
  • Is this related to your case? http://stackoverflow.com/questions/32445546/django-uuidfield-modelfield-causes-error-in-django-admin-badly-formed-hexadecim – kaveh Mar 28 '17 at 22:20
  • I followed the step in there, and reset my db, `python manage.py flush`, but still error shows up. – KhoPhi Mar 28 '17 at 22:21

1 Answers1

0

Figured.

The url sequence was the culprit. Having sequence this way fixed it:

url(r'^travel/add/$', views.TravelAdd.as_view(), name='travel_add'),
url(r'^travel/list/$', views.TravelList.as_view(), name='travel_list'),
url(r'^travel/(?P<uuid>[\w-]+)/$', views.TravelDetail.as_view(), name='travel_detail'),

Previously, it was this:

url(r'^travel/add/$', views.TravelAdd.as_view(), name='travel_add'),
url(r'^travel/(?P<uuid>[\w-]+)/$', views.TravelDetail.as_view(), name='travel_detail'),
url(r'^travel/list/$', views.TravelList.as_view(), name='travel_list'),
KhoPhi
  • 9,660
  • 17
  • 77
  • 128
  • 1
    Right, `list` matches that regexp. You could be stricter with something like `(?P[a-f0-9]{8}-[a-f0-9]{4}-...)/$` if you want to avoid worrying about it in the future. – Peter DeGlopper Mar 28 '17 at 22:28