Django.get () throws a DoNotExist error without explicitly searching for "__exact"

I ran into a problem that I can neither understand nor google, and then followed the steps from the book Practical Django Projects.

The example code of the view below should return a specific Entry object (I skipped the unnecessary part), but it causes the error "DoNotExist: Record Match Error":

...
return render_to_response('weblog/entry_detail.html',
                          {'entry':Entry.objects.get(pub_date__year=pub_date.year,
                                           pub_date__month=pub_date.month,
                                           pub_date__day=pub_date.day,
                                           slug=slug)

(I confirmed that the target really exists, etc.)

When I replaced the .get () method with the filter () method, it returned me a request with my target.

After some sessions of "hitting the wall" I managed to do the job with the call .get () when replacing

   slug=slug

with

   slug__exact=slug

. , Django docs , "__exact" (Django 1.6, " " )

SQL-, Django .get(), SQL-, .filter() ( , ).

, 2 (filter() [0] "__exact" ), .get().

:

  • "__exact" ?
  • , Django/DB?
  • SQL-, Django, ?

!

: Django 1.6.1/Python 2.7.3/MySQL 5.5.33

. django-debug .get() . , , - "", , :

  • = :

    SELECT weblog_entry. id, weblog_entry. title, weblog_entry. excerpt, weblog_entry. body, weblog_entry. pub_date, weblog_entry. excerpt_html weblog_entry. body_html, weblog_entry. author_id, weblog_entry. slug, weblog_entry. status, weblog_entry. enable_comments, weblog_entry. featured FROM weblog_entry WHERE (EXTRACT (MONTH FROM CONVERT_TZ (weblog_entry. pub_date, 'UTC', 'UTC')) = 2 AND weblog_entry. pub_date BETWEEN '2014-01-01 00:00:00 '' 2014-12-31 23:59:59 ' EXTRACT ( CONVERT_TZ (weblog_entry. pub_date,' UTC ',' UTC ')) = 2 AND weblog_entry. slug =' 3rd-entry ')

  • slug__exact = :

    SELECT weblog_entry. id, weblog_entry. title, weblog_entry. excerpt, weblog_entry. body, weblog_entry. pub_date, weblog_entry. excerpt_html weblog_entry. body_html, weblog_entry. author_id, weblog_entry. slug, weblog_entry. status, weblog_entry. enable_comments, weblog_entry. featured FROM weblog_entry WHERE (EXTRACT (MONTH FROM CONVERT_TZ (weblog_entry. pub_date, 'UTC', 'UTC')) = 2 AND weblog_entry. pub_date BETWEEN '2014-01-01 00:00:00 '' 2014-12-31 23:59:59 ' weblog_entry. slug =' 3rd-entry ' EXTRACT ( CONVERT_TZ (weblog_entry. pub_date,' UTC ',' UTC ' )) = 2)

. mysql, ;

Update2. , .

+3
1

, .

"__exact" ?

, . django doc:

, (, Entry.objects.get(id = 14)) .

- , :

, Django/DB?

, . Django ,

SQL-, Django , ?

:)

+1

All Articles