You can read the short blog article that gives a [description of what I was thinking](http://unpythonic.blogspot.com/2007/03/using-pexpect-to-control-django.html)
when I attempted this. Note: UNIX only. Sorry!
Sometimes you'll have a list of ORM objects that aren't in a QuerySet, but you still want to sort them by date. For instance, you have a list of shows with a date_time attribute. Maybe you used a list comprehension to filter them...who knows. Regardless, you have a list (not a QuerySet) of Django objects.
This is like [snippet 36](/snippets/36/). And it'll return css also. And it's not a filter.If the code parameter is skip, it'll test the code first, and if there is not a suiable lexer for the code, then use default python lexer to render the code. The code lanauage parameter is comes from pygments lexer alias.
How to use it
----------------
html = to_html(rest_text)
And there is a level parameter in to_html function, default is `2`, it's the sections level. And the html will be `css style + body`
How to write ReST
---------------------
Below is a example.
This is a test.
.. code::
def code(name, arguments, options, content, lineno,
content_offset, block_text, state, state_machine):
opt = {'display':'on'}
opt.update(options)
docnodes.Node(content, ''.join(arguments), **opt)
if opt['display'].lower() == 'on':
return [nodes.literal_block('', '\n'.join(content))]
else:
return []
.. code:: html+django
<h1 id="title">通讯录</h1>
<hr>
<div>
<table border="0" width="500">
<tr align="right">
<td>{% if has_previous %}
<a href="/address?page={{ previous }}">上一页</a>
{% endif %} {% if has_next %}
<a href="/address?page={{ next }}">下一页</a>
{% endif %}</td></tr>
</table>
This code is derived from the slugify JS function used in django's admin interface. It will create django-compatible slugs for you. Sometimes I do batch imports and need my items to have slugs, I give this script the item's title and get a slug back.
Simple
Convert plain text to html. For example:
text="""aabhttp://www.example.com http://www.example.com
http://www.example.com <<< [<aaaa></aaaa>]
"""
print plaintext2html(text)
It can convert url text to html href. And it also can convert space to . So if you paste python code, the indent will not lost at all. Default it'll convert \t to 4 spaces.
A more simple version of [https://djangosnippets.org/snippets/1688/](https://djangosnippets.org/snippets/1688/), inheriting from `SelectDateWidget`, overriding only the necessarily.
**Usage example:**
**In models.py:**
from django.db import models
from django.utils.translation import gettext_lazy as _
class MyModel(models.Model):
start = models.DateField(
_("Start date"),
)
end = models.DateField(
_("End date"),
)
class Meta:
verbose_name = _("My model")
**In forms.py:**
from django import forms
from .models import MyModel
from .widgets import MonthYearWidget
class MyModelForm(forms.ModelForm):
class Meta:
model = MyModel
exclude = []
widgets = {
"start": MonthYearWidget(),
"end": MonthYearWidget(last_day=True),
}
**kwargs:**
- *last_day :* if set to `True`, returns the last day of the month in the generated date.
Third party services (e.g. Stripe) optionally sign webhook events to verify it is them sending events. If the third party you use does not provide an SDK or official library for verifying signatures, you can manually verify the signature with this snippet.
As you can see, if you using django-rest-framework, you will found many different response format. This middleware to solve all of these problems with Standard API Response.
All HTTP Response status stored into json response, not in HTTP Status (because mobile application, like android can't fetch the response body when HTTP Status >= 400).
let say the user chooses the name "Elsa Frozen"
now his slug would be "Elsa-Frozen-5"
it means 4 other people have used the same header
now he can go to url: "your website.com/Elsa-Frozen-4" to see other people's Post
Use this to display an object on a page AND be able to process a form on this page.
This is just a copy of the [Django docs advice](https://docs.djangoproject.com/en/2.2/topics/class-based-views/mixins/#using-formmixin-with-detailview), but put as a reusable, standalone View.
You're looking at the most-bookmarked snippets on the site; if you'd like to help useful snippets show up here, sign up for an account and you'll get your own bookmarks list.