From trydjango1.10 https://www.youtube.com/playlist?list=PLEsfXFp6DpzQSEMN5PXvEWuD2gEWVngCZ
mkdir django1.10
cd django1.10/
virtualenv py3 -p python3
. py3/bin/activate
pip install django==1.10.3
django-admin.py startproject shortme
cd shortme
python manage.py startapp shortener
python manage.py migrate
python manage.py createsuperuser
python manage.py makemigrations
python manage.py migrate
python manage.py migrate shortener --fake
python manage.py shell
from shortener.models import ShortURL
ShortURL.objects.all()
url1 = ShortURL.objects.create()
url1.url = "http://www.epfl.ch"
url1.shortcode = "home"
url1.save()
url2, created = ShortURL.objects.get_or_create(url="http://www.epfl.ch")
created
url2.shortcode
url3 = ShortURL.objects.get(url="www.google.com")
ShortURL.objects.get_or_create(url="http://www.google.com", shortcode="google")
ShortURL.objects.get_or_create(url="http://www.google.com", shortcode="google")
https://docs.djangoproject.com/en/1.10/howto/writing-migrations/#migrations-that-add-unique-fields
rm -rf shortener/migrations/*
rm db.sqlite3
python manage.py makemigrations shortener
python manage.py createsuperuser
python manage.py shell
In [1]: from shortener.models import ShortURL
In [2]: ShortURL.objects.all().count()
Out[2]: 4
In [3]: ShortURL.objects.count()
Out[3]: 5
In [4]: for u in ShortURL.objects.filter(id__gte=1): print(u.shortcode)
12EZ4I
home
google
bb
k5mdcx
In [5]: ShortURL.objects.regenerate_all_shortcodes()
In [6]: for u in ShortURL.objects.filter(id__gte=1): print(u.shortcode)
w7wfb8
2omn03
wkkypy
4ej8uj
x0grn0
python manage.py dumpurls
zts5ze -> http://enacit.epfl.ch
age9m9 -> http://www.epfl.ch
u66ec3 -> http://www.google.com
l6zou4 -> http://example.com
python manage.py refreshcodes
python manage.py dumpurls
7k95wc -> http://enacit.epfl.ch
axdpd2 -> http://www.epfl.ch
n17jsw -> http://www.google.com
bbqfwq -> http://example.com
http://127.0.0.1:8000/ http://127.0.0.1:8000/view-1/ http://127.0.0.1:8000/view-2/
http://127.0.0.1:8000/a/Alice/ http://127.0.0.1:8000/b/Bob/
http://django-hosts.readthedocs.io/en/latest/
127.0.0.1 shortme.com www.shortme.com blog.shortme.com
pip install django-hosts
http://blog.shortme.com:8000/a/axdpd2/
python manage.py makemigrations
python manage.py migrate
Test on
http://getbootstrap.com/getting-started/#download http://getbootstrap.com/examples/cover/
List required packages
pip freeze --local > requirements.txt
Install required packages on server
pip install -r requirements.txt
- Compression (js/css)
- API
- JSON
- https://docs.python.org/3/library/json.html
- django.core.serializers.json