Closed jonsaul closed 8 years ago
No, definitely not a stupid question :).
This is actually supported out of the box:
{% for post in posts %}
<a href="{% url post.path %}">{{ post.title }}</a>
{% endfor %}
(the {% url ... %}
mechanism is documented in the README)
Then, enable prettify
in your configuration. This is documented in the README as well.
Cheers,
Hi thanks for your quick response on this: your answer makes perfect sense to me and I have been through the steps your suggested, I am still experiencing some issues with this, in order to test I cloned the example blog from github and tried to use this method on there , I can see that in the build folder the posts are now moved into a directory and an 'index.html' has been created for each, I still get the same response though when I attempt to link to a post using {% url post.path %}
this makes me think I am missing some additional config setting maybe, the url still returns the post with the html extension and is not found Sorry the page /posts/third-post.html could not be found on this server.
for example...
also getting this output to the console during build
/index.html: page resource does not exist: posts/third-post.html
/index.html: page resource does not exist: posts/second-post.html
/index.html: page resource does not exist: posts/first-post.html
/posts/first-post.html: static resource does not exist: favicon.ico
/posts/first-post.html: static resource does not exist: static/css/master.css
/posts/first-post.html: page resource does not exist: posts/second-post.html
/posts/second-post.html: static resource does not exist: favicon.ico
/posts/second-post.html: static resource does not exist: static/css/master.css
/posts/second-post.html: page resource does not exist: posts/first-post.html
/posts/second-post.html: page resource does not exist: posts/third-post.html
/posts/third-post.html: page resource does not exist: posts/second-post.html
Duh. That blog plugin is a mess : (...
All right, here's what you should do:
plugins/blog.py
, add postContext['page'] = page
below all the other postContext['page]' = ...
statements{% for post in posts %}
<a href="{% url post.page.link_url %}">{{ post.title }}</a>
{% endfor %}
Cheers,
Amazing, working perfectly now. Thank you so much :)
Awesome; happy to help : )
HI, looking for an idea on the correct way to work around an issue I have when using the pretty urls and calling
/{{ post.path }}
my posts are html files and so the resulting url I get back is"/posts/foo.html"
which will display"Sorry the page /posts/foo.html could not be found on this server."
So essentially my issue is that in a page called "posts.html" (rendered url is /posts/) I am doing something like:
{% for post in posts %} <a href="/{{ post.path }}">{{post.title}}</a> {% endfor %}
and getting the message
"Sorry the page /posts/foo.html could not be found on this server."
Any ideas on how I dynamically pull the post.path to return something more like
/posts/foo/
, if I manually remove.html
from the url the page will render correctly.Hopefully this isn't a stupid question...