Django 2.0 path error ?: (2_0.W001) has a route that contains ‘(?P

The new path() syntax in Django 2.0 does not use regular expressions. You want something like: path(‘<int:album_id>/’, views.detail, name=”detail”), If you want to use a regular expression, you can use re_path(). re_path(r’^(?P<album_id>[0-9])/$’, views.detail, name=”detail”), The old url() still works and is now an alias to re_path, but it is likely to be deprecated in future. … Read more

How to get primary keys of objects created using django bulk_create

2016 Since Django 1.10 – it’s now supported (on Postgres only) here is a link to the doc. >>> list_of_objects = Entry.objects.bulk_create([ … Entry(headline=”Django 2.0 Released”), … Entry(headline=”Django 2.1 Announced”), … Entry(headline=”Breaking: Django is awesome”) … ]) >>> list_of_objects[0].id 1 From the change log: Changed in Django 1.10: Support for setting primary keys on objects … Read more

Can I call a view from within another view?

Sure, as long as when it’s all said and done your view returns an HttpResponse object. The following is completely valid: def view1(request): # do some stuff here return HttpResponse(“some html here”) def view2(request): return view1(request) If you don’t want to return the HttpResponse from the first view then just store it into some variable … Read more