I followed the tutorial on https://django-comments-xtd.readthedocs.io, everything seems to work find, the forms and the comments are working, but on the website they are not displayed properly.
instead of looking like this:
They all look like this
The reply is not nesting under the comment
but in the admin its working you can see how it nests
take a look:
Please help
Try add css class container in the comment_tree.html
<div class="container media">
Related
Trying to use {{ post|truncatewords:"100" }} for a teaser in Cactus. The post is using the markdown filter and truncate words is showing the html. I also tried {{ post|truncatewords:"100"|markdown }} which does seem like it is attempting to format correctly, however line breaks and body tags still show.
Example Output:
{'body': u'\n\n
Cactus templates are set up using the Django Template Language. Django\u2019s template language is both powerful and easy to use. A template is simply a HTML file. Let\'s take a look at how to use the blog template.
\n\n
General file str...
Seems like this should be pretty straight forward but I cannot figure out what I am doing wrong.
Any help would be greatly appreciated.
Thanks.
Looks like post is a dictionary, and the post body you want to show is under the body key. You probably want something like:
{{ post.body|markdown|truncatewords_html:100 }}
I've started using Django and am going right to generic views. Great architecture! Well, the documents are great, but for the absolute beginner it is a bit like unix docs, where they make the most sense when you already know what you're doing. I've looked about and cannot find this specifically, which is, how do you set up an object_list template so that you can click on an entry in the rendered screen and get the object_detail?
The following is working. The reason I'm asking is to see if I am taking a reasonable route or is there some better, more Djangoish way to do this?
I've got a model which has a unicode defined so that I can identify my database entries in a human readable form. I want to click on a link in the object_list generated page to get to the object_detail page. I understand that a good way to do this is to create a system where the url for the detail looks like http://www.example.com/xxx/5/ which would call up the detail page for row 5 in the database. So, I just came up with the following, and my question is am I on the right track?
I made a template page for the list view that contains the following:
<ul>
{% for aninpatient in object_list %}
<li><a href='/inpatient-detail/{{ aninpatient.id }}/'>{{ aninpatient }}</a></li>
{% endfor %}
</ul>
Here, object_list comes from the list_detail.object_list generic view. The for loop steps through the object list object_list. In each line I create an anchor in html that references the desired href, "/inpatient-detail/nn/", where nn is the id field of each of the rows in the database table. The displayed link is the unicode string which is therefore a clickable link. I've set up templates and this works just fine.
So, am I going in the right direction? It looks like it will be straightforward to extend this to be able to put edit and delete links in the template as well.
Is there a generic view that takes advantage of the model to create the detail page? I used ModelForm helper from django.forms to make the form object, which was great for creating the input form (with automatic validation! wow that was cool!), so is there something like that for creating the detail view page?
Steve
If you're on django < 1.3 then what you are doing is basically perfect. Those generic views are quite good for quickly creating pages. If you're on django 1.3 you'll want to use the class based generic views. Once you get a handle on those they are are crazy good.
Only note I have is that you should use {% url %} tags in your templates instead of hardcoding urls. In your urls.conf file(s) define named urls like:
url('inpatient-detail/(?P<inpatient_id>\d+)/$', 'your_view', name='inpatient_detail')
and in your template (for django < 1.3):
...
In 1.3 a new url tag is available that improves life even more.
I want to divide index page into small stand alone .html parts like:
up_bar.html:
<p><center>
<h1>home</h1>
Menu: home add import
down_bar.html:
<a href="/path/.."/>
and so on.
Now, to build a new page is it possible to embed those pieces into other page using default webpy templator?
Maybe something like that?:
in admin.html:
$def with(some_parameters):
<title>Admin panel</title>
$include('side_bar.html')
... body stuff ...
$include('down_bar.html')
A basic but good introduction to template inheritance can be found here: http://webpy.org/cookbook/layout_template
Found an answer here: http://groups.google.com/group/webpy/msg/ea6da02dfb9eedc4?dmode=source
Some explanation will be great.
I did this to my code
def GET(self,*args):
param= {'name':'jackie'}
view = web.template.frender("views/someview.html")
content = view(**param)
layout = web.template.frender("views/index.html")
return layout(content=content)
now you just insert $:content in index.html
If i go to www.mysite.com/login, everything displays like it should.
But when i want to go from mysite.com/login to mysite.com/register, i end up in mysite.com/login/register.
How can i solve this problem?
It is hard to tell without some code but I guess on your login site you have a link like:
Register
which should probably be
<a href="{% url name_of_register_url %}>Register</a>
Can you provide your url.py and the HTML code for that link?
My Django app has a Person table, which contains the following text in a field named details:
<script>alert('Hello');</script>
When I call PersonForm.details in my template, the page renders the script accordingly (a.k.a., an alert with the word "Hello" is displayed). I'm confused by this behavior because I always thought Django 1.0 autoescaped template content by default.
Any idea what may be going on here?
UPDATE: Here's the snippet from my template. Nothing terribly sexy:
{{ person_form.details }}
UPDATE 2: I have tried escape, force-escape, and escapejs. None of these work.
You need to mark the values as | safe I think (I'm guessing that you're filling in the value from the database here(?)):
{{ value|safe }}
Could you post a sample of the template? Might make it easier to see what's wrong
[Edit] ..or are you saying that you want it to escape the values (make them safe)? Have you tried manually escaping the field:
{{ value|escape }}
[Edit2] Maybe escapejs from the Django Project docs is relevent:
escapejs
New in Django 1.0.
Escapes characters for use in JavaScript strings. This does not make the string safe for use in HTML, but does protect you from syntax errors when using templates to generate JavaScript/JSON.
[Edit3] What about force_escape:
{{ value|force_escape }}
...and I know it's an obvious one, but you're absolutely certain you've not got any caching going on in your browser? I've tripped over that one a few times myself ;-)
Found the problem. The JSON string I'm using to render data to some Ext widgets is the culprit. Big thanks to Jon Cage. Answer accepted despite the problem being caused by another source.