Snippet List
Takes a tweet url, requests the json from Twitter oEmbed, parses the json for the html element and returns it to your template. The html returned is ready to go and will be shown as a tweet on your web page. This uses the Requests library for Python. A full example can be found on GitHub https://github.com/z3ke1r/django-tweet-embed.
- django
- templatetag
- json
- embed
- twitter
- parse
- requests
- tweet
Django Template Filter that parse a tweet in plain text and turn it with working Urls
Ceck it on [GitHub](https://github.com/VincentLoy/tweetparser-django-template-filter)
# tweetParser Django Template Filter
this is a port of [tweetParser.js](https://github.com/VincentLoy/tweetParser.js) to work as a Django template filter
## How does it work ?
Once installed, just :
```
<p>{{ your_tweet|tweetparser }}</p>
```
## Installation
Take a look at the [Django Documentation](https://docs.djangoproject.com/en/1.8/howto/custom-template-tags/)
#### You can change the classes given to each anchor tags
```
USER_CLASS = 'tweet_user'
URL_CLASS = 'tweet_url'
HASHTAG_CLASS = 'hashtag'
```
- filter
- templatetag
- templatetags
- twitter
- parse
- parser
- tweet
Позволяет получить типизированный словарь из входных параметров.
Может быть использован, например, для дальнейшей передаче параметров в objects.filter(**rez).
From: [incredible times](http://incredibletimes.org)
With inspiration from: [Unethical Blogger](http://unethicalblogger.com/2008/05/03/parsing-html-with-python.html)
This code parses any provided HTML content, and extracts a number of paragraphs specified, with all the content and tags inside them.
Example:
Template variable "content" contains:
<a href="#>some text</a>
<p><strong>Testing</strong>testing testing this is a tester's life</p>
<div>I wont see the world</div>
<p>Another paragraph</p>
So, place this code in any loaded template module (inside a templatetags folder of your app... i.e. myapp/templatetags/myutils.py)
{% load myutils %}
{{ content|paragraphs:"1"}}
Would return:
<p><strong>Testing</strong>testing testing this is a tester's life</p>
Whereas
{% load myutils %}
{{ content|paragraphs:"2"}}
Returns:
<p><strong>Testing</strong>testing testing this is a tester's life</p>
<p>Another paragraph</p>
- filter
- paragraph
- html
- parse
- extract
Enhanced version of snippet [1113](http://djangosnippets.org/snippets/1113/)
Usage example (not self-contained):
@register.tag
def groupurl(parser, token):
'''
Syntax::
{% groupurl view_name group [key=val, [key=val, ...]] [as varname] %}
Example::
<a href="{% groupurl blog_detail group slug=blog.slug %}">{{ blog.name }}</a>
'''
bits = token.contents.split()
tag_name = bits[0]
if len(bits) < 3:
raise template.TemplateSyntaxError("'%s' takes tag at least 2 arguments (path to a view and a group)" % (tag_name,)
bits_iter = iter(bits[1:])
# view_name + group and url kwargs
args, kwargs = parse_args_and_kwargs(parser, bits_iter, stop_test='as', tagname=tag_name)
if len(args) != 2:
raise template.TemplateSyntaxError("'%s' takes exactly two non-kwargs (path to a view and a group)" % (tag_name,))
view_name, group = args
# as var
asvar = None
for bit in bits_iter:
asvar = bit
return GroupURLNode(view_name, group, kwargs, asvar)
- tag
- templatetag
- parse
- args
- kwargs
Return a datetime corresponding to date_string, parsed according to format.
I had the need for such a thing while working with an API that returned JSON that I fed, via simplejson, directly to a template, and didn't want to change the data structure just for this one piece.
At WWU Housing, we started using the [Tempest jQuery plugin](http://plugins.jquery.com/project/tempest) for javascript templating, which has the same {{ var }} syntax as Django's templating.
We wanted to be able to use the same templates in our server-side python and our client-side js, so we had to have a way of including the unrendered template for the js. At the same time, for convenience, it had to be modular so we could push the same code from our dev- to our live-server and not worry about absolute paths (which is why the {% ssi %} tag did not work).
So the {% include_raw %} tag was born.
- template
- django
- parse
- include
- ssi
A simple function that will remove the quote marks from every string in a list - if and only if the quote marks are the first and last character of the string, regardless of whether they are single or double quotes.
Useful when parsing the arguments of a custom tag.
- quotes
- parse
- custom-tags
- tokens
10 snippets posted so far.