абстрактных классов
from abc import ABCMeta, abstractmethod
class Abstract(object):
__metaclass__ = ABCMeta
@abstractmethod
def foo(self):
pass
Abstract()
>>> TypeError: Can not instantiate abstract class Abstract with abstract methods foo
class B(Abstract):
pass
B()
>>> TypeError: Can not instantiate abstract class B with abstract methods foo
не нашел интерфейсов
приватных методов
- многопоточность
- строгая типизация
BASE_DIR = path.abspath(path.join(path.dirname(__file__), '..')) # выходим за пределы директории "проекта"
TEMPLATE_DIRS = (
path.join(BASE_DIR, 'templates') # порядок сложения путей важен!
)
<form method="POST" enctype="multipart/form-data">...
Source = "My name is {{ name }}.",
{ok, Tpl} = dtl_template:new(Source),
Ctx = dtl_context:new([
{name, "Lawrence"}
]),
{ok, <<"My name is Lawrence">>} = dtl_template:render(Tpl, Ctx).
class TextTemplate(models.Model):
....
def get_absolute_file_upload_url(self):
return MEDIA_URL + self.file_upload.url
#urls.py
...
urlpatterns = patterns(
'',
url(r'^text-template/(?P<primary_key>\d+)/$', get_tt),
url(r'^text-template/$', get_all_tt),
)
...
#view.py
def get_tt(request, primary_key):
tt_item = TextTemplate.objects.get(pk=primary_key)
# or
# tt_item = get_or_404(TextTemplate, pk=primary_key)
print tt_item.file_upload.url
return render('t.html', {'tt': tt_item})
def get_all_tt(request):
tt_all = TextTemplate.objects.all()
for tt_item in tt_all:
print tt_item.file_upload.url
return render('tt-all.html', {'tt': tt_all})
#t.html
<img src="{{ MEDIA_URL }}{{ tt.url }}">
<br>
<img src="{{ tt.get_absolute_file_upload_url }}">
#tt-all.html
{% for tt in tt_all %}
<img src="{{ tt.get_absolute_file_upload_url }}">
{% endfor %}
Options.unique_together
Sets of field names that, taken together, must be unique:
unique_together = (("driver", "restaurant"),)
This is a tuple of tuples that must be unique when considered together. It’s used in the Django admin and is enforced at the database level (i.e., the appropriate UNIQUE statements are included in the CREATE TABLE statement).
For convenience, unique_together can be a single tuple when dealing with a single set of fields:
unique_together = ("driver", "restaurant")
class TTest(models.Model):
t1 = models.IntegerField()
t2 = models.IntegerField()
class Meta:
unique_together = ('t1', 't2')
$python manage.py sql ttest
BEGIN;
CREATE TABLE "ttest_ttest" (
"id" integer NOT NULL PRIMARY KEY,
"t1" integer NOT NULL,
"t2" integer NOT NULL,
UNIQUE ("t1", "t2")
)
;
COMMIT;
<html class="no-js">
http://nginx.org/packages/ubuntu/dists/
sudo apt-get source nginx
export CFLAGS=-Qunused-arguments
export CPPFLAGS=-Qunused-arguments
sudo -E pip install psycopg2
Гугл ничего не показал