DjangoGirls / tutorial-extensions

Additional tasks for tutorial
https://tutorial-extensions.djangogirls.org
Other
163 stars 203 forks source link

'Post' object has no attribute 'publish' #50

Closed smileyninja closed 8 years ago

smileyninja commented 8 years ago

I get the following error when I click on the "Publish" button. I think the alignment in my post_detail.html file may be off and causing the problem. Is the source code listed somewhere?

AttributeError at /post/4/publish/ 'Post' object has no attribute 'publish' Request Method: GET Request URL: http://127.0.0.1:8000/post/4/publish/ Django Version: 1.9.4 Exception Type: AttributeError Exception Value:
'Post' object has no attribute 'publish' Exception Location: /home/kevin/djangogirls/blog/views.py in post_publish, line 56 Python Executable: /usr/bin/python Python Version: 2.7.11 Python Path:
['/home/kevin/djangogirls', '/usr/local/lib/python2.7/dist-packages/setuptools-20.2.2-py2.7.egg', '/usr/lib/python2.7/dist-packages', '/usr/local/lib/python2.7/dist-packages/lgogd_uri-0.1.0.1-py2.7.egg', '/usr/lib/python2.7', '/usr/lib/python2.7/plat-x86_64-linux-gnu', '/usr/lib/python2.7/lib-tk', '/usr/lib/python2.7/lib-old', '/usr/lib/python2.7/lib-dynload', '/home/kevin/.local/lib/python2.7/site-packages', '/usr/local/lib/python2.7/dist-packages', '/usr/lib/python2.7/dist-packages/PILcompat', '/usr/lib/python2.7/dist-packages/gtk-2.0', '/usr/lib/python2.7/dist-packages/wx-3.0-gtk2']

metlem commented 8 years ago

I have the same error :(

Zaccc123 commented 8 years ago

Hi @metlem and @smileyninja , i believe the errors is the wrong urls.

Change from this:

<a class="btn btn-default" href="{% url 'blog.views.post_publish' pk=post.pk %}">Publish</a>

To

<a class="btn btn-default" href="{% url 'post_publish' pk=post.pk %}">Publish</a>

Some of the urls is not updated, i have submitted a pull request #52 that fixed it. Hopefully it will get approve soon. If in any part of the tutorial, your see this blog.views.post_publish just remove the blog.views. prefix and it should work.

helenst commented 8 years ago

The fix for this has been merged now. Thank you! :+1:

xoroz commented 7 years ago

I was having same problem but I forgot to ident in the models.py :(

Anyway found same "bug" on another part With Python 3.5 and Django 1.10.4 BUG: return redirect('blog.views.post_detail', pk=post.pk) TO: return redirect('post_detail', pk=post.pk)

ref: https://docs.djangoproject.com/en/1.10/topics/http/shortcuts/

helenst commented 7 years ago

Hi @xoroz please could you tell us where in the tutorial you found that line of code?