- Какие типы данных в питоне mutable\immutable?
- mutable:
- list
- dict
- set
- byte array
- immutable
- Numeric types: int, float, complex
- string
- mutable:
- tuple
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
terraform { | |
required_version = "~> 0.12" | |
backend "consul" { | |
address = "consul.local" | |
scheme = "http" | |
path = "terraform/services/resizer" | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{% extends 'base.html' %} | |
{% load static %} | |
{% load i18n %} | |
<script type="text/javascript" src="{% static 'js/jquery-1.6.1.min.js' %}"></script> | |
<script type="text/javascript" src="{% static 'plugin/jquery-jplayer/jquery.jplayer.js' %}"></script> | |
<script type="text/javascript" src="{% static 'plugin/ttw-music-player-min.js' %}"></script> | |
<link href="{% static 'plugin/css/style.css' %}" rel="stylesheet" type="text/css"/> | |
<script type="text/javascript"> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from rest_framework import generics, permissions | |
from .serializers import UserSerializer, PostSerializer, PhotoSerializer | |
from .models import User, Post, Photo | |
class UserList(generics.ListCreateAPIView): | |
model = User | |
serializer_class = UserSerializer |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.conf.urls import patterns, url, include | |
from .api import UserList, UserDetail | |
from .api import PostList, PostDetail, UserPostList | |
from .api import PhotoList, PhotoDetail, PostPhotoList | |
user_urls = patterns('', | |
url(r'^/(?P<username>[0-9a-zA-Z_-]+)/posts$', UserPostList.as_view(), name='userpost-list'), | |
url(r'^/(?P<username>[0-9a-zA-Z_-]+)$', UserDetail.as_view(), name='user-detail'), | |
url(r'^$', UserList.as_view(), name='user-list') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>>> from example.api.models import User | |
>>> user = User.objects.get(username='bob') | |
>>> from example.api.serializers import * | |
>>> serializer = UserSerializer(user) | |
>>> serializer.data | |
{'id': 2, 'username': u'bob', 'first_name': u'Bob', 'last_name': u'', 'posts': '/api/users/bob/posts'} | |
>>> post = user.posts.all()[0] | |
>>> PostSerializer(post).data | |
{'author': {'id': 2, 'username': u'bob', 'first_name': u'Bob', 'last_name': u'', 'posts': '/api/users/bob/posts'}, 'photos': '/api/posts/2/photos', u'id': 2, 'title': u'Title #2', 'body': u'Another thing I wanted to share'} | |
>>> serializer = PostSerializer(user.posts.all(), many=True) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from rest_framework import serializers | |
from .models import User, Post, Photo | |
class UserSerializer(serializers.ModelSerializer): | |
posts = serializers.HyperlinkedIdentityField('posts', view_name='userpost-list', lookup_field='username') | |
class Meta: | |
model = User |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.core import serializers | |
data = serializers.serialize("xml", SomeModel.objects.all()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.db import models | |
from django.contrib.auth.models import AbstractUser | |
class User(AbstractUser): | |
followers = models.ManyToManyField('self', related_name='followees', symmetrical=False) | |
class Post(models.Model): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sudo apt-get install libxml2 | |
sudo apt-get install libxslt1.1 | |
sudo apt-get install libxml2-dev | |
sudo apt-get install libxslt1-dev | |
sudo apt-get install python-libxml2 | |
sudo apt-get install python-libxslt1 | |
sudo apt-get install python-dev | |
sudo apt-get install python-setuptools | |
pip install lxml |