Unable to retrieve data in django -


I am writing a weblog application in the digengo. As part of this, I have a visual function that brings the object from the database corresponding to a blog post. The field that I am using to query the database is the published date (pub_date) that is the date time (python). I have a MySQL database and the type of column for this field is datetime but I can not get the object from the database, although I am passing the correct date attributes. I'm getting a 404 error. The following is my visual function:

  def entry_data (request, year, month, day, slug): import date time, time date_stamp = time.strptime (year + month + day, "% Y % B% d ") PUB_DATE = datetime.date (* date_stamp [: 3]) entry = get_object_or_404 (entry, pub_date__year = pub_date.year, pub_date__month = pub_date.month, pub_date__day = pub_date.day, slug = slug) returns render_to_response 'Coltrane / entry_detail.html', {'Entry': Entry})  

Below is the URL of the individual post I want to receive:

 < Code> http://127.0.0.1:8000/weblog/2014/oct/28/third-post/  

and thus pub_date seems to be the third term in the column value database:

  2014-10-28 13:26:39  < / Pre> 

The following URL pattern is:

  url (r '^ weblog / (? P> year & gt; \ d {4}) / (? P & lt ; Month & gt; \ w {3}) / (? P & lt; days & gt; \ {2}) / (? P & lt; slug & gt; [- \ w] +) / $ ', 'Coltrane.views.entry_detail'),  

You're doing some weird things here Are: If you convert to a time , then there is a datetime that changes .date , then complete the year, month and day. Remove as Ank and pass them to the query. You can bypass the whole process: Only one thing you need to convert to the month, other parameters can be passed directly:

  month_no = datetime.datetime.strptime (month, '% B') .month entry = get_object_or_404 (entry, pub_date__year = year, pub_date__month = month_no, pub_date__day = day, slug = slug)  

Comments

Popular posts from this blog

java - Can't add JTree to JPanel of a JInternalFrame -

javascript - data.match(var) not working it seems -

javascript - How can I pause a jQuery .each() loop, while waiting for user input? -