2👍
You can use the template tag
: safe.
Let’s say that your post context variable is: quote
= @Mike is a fool
Grab @Mike
, and add the html
to make it a link and reinsert it when saving the post. So the saved post is:
quote
= <a href="mikes_homepage">@Mike</a> is a fool
And then use safe in your html template
:
{{ quote|safe }}
Here is the documentation link for safe
template tags:
https://docs.djangoproject.com/en/dev/ref/templates/builtins/#safe
0👍
Facebook asks from the browser to their database at each keypress after @
. As soon as you select the user name, lets say @Mike
they add an input field to the form with the value you selected, something like:
<input value="@12345678:Mike"></input>.
You submit the comment, and the server processes your request, substituting @Mike
in your textbox with whatever they want using the <input>
value.
- [Answered ]-Django ClearableInputField in form doesn't render in HTML
- [Answered ]-Django model formset performance
0👍
this should work
after you save your form put this script
p = re.compile('@[a-z]+')
for word in yourform.comment.split():
if p.match(word) != None:
new_word=list(word)[1:len(list(word))]
name=''
for elenemts in new_word:
name += elements
write below line in ‘if’ condition(not able to write here with proper indentation)
new_comment=re.sub('@[a-z]+','<a href='+name+'s_profile>'+name+'</a>',yourform.comment)`
now in your template render your “new_comment” as safe
{{ new_comment|safe }}
- [Answered ]-Django: global variables in multi-connections
- [Answered ]-Creating an API using Django-Rest-Framework with join tables
- [Answered ]-How to redirect to another view with parameter in this example?
- [Answered ]-Openshift Custom Cartridge with Python 3.4
- [Answered ]-DjangoRestFramework – How do I customize the frontend?