Forwarded from Deleted Account
جلسه ۴۹ گروه کاربران پایتون تهران، پنجشنبه ۱۱ آبان ۱۳۹۶ از ساعت ۱۴:۳۰ تا ۱۶:۰۰ در «شتابدهندهٔ آواتک» به نشانی «تهران، خیابان کارگر شمالی، بالاتر از بزرگراه جلال آل احمد، پردیس دانشکدههای فنّی دانشگاه تهران، دانشکدهٔ مهندسی نفت، طبقهٔ پنجم» برگزار خواهد شد.
در صورتی که داوطلب ارائه فنی هستید موضوع ارائه خود را به میلینگ لیست گروه کاربران پایتون تهران ارسال کنید.
https://mail.python.org/mailman/listinfo/tehpug
یا به بنده پی ام دهید.
در صورتی که داوطلب ارائه فنی هستید موضوع ارائه خود را به میلینگ لیست گروه کاربران پایتون تهران ارسال کنید.
https://mail.python.org/mailman/listinfo/tehpug
یا به بنده پی ام دهید.
PART-1: Basic docker commands
* Let's suppose you have built an image.
Display list of your docker images:
Output:
As you can see image name is
To run the image:
The above command runs the docker image. The newly created processs by
host, and the second port
Now to see list of your containers use
From here you can see the ID of your container which is equal to
ontainer (login into container):
if you want to connect to the stdout of your container use
*** IF you are attached to a container and press ^c afterward, the container will be stopped.
If you want to stop a container:
It prints out container id
#docker #commands #docker_part1 #basic #container #devops
* Let's suppose you have built an image.
Display list of your docker images:
docker images
Output:
REPOSITORY TAG IMAGE ID CREATED SIZE
py_app latest baa470dc5609 3 weeks ago 591MB
As you can see image name is
py_app
.To run the image:
docker run -it -d -p 8085:8084 py_app
The above command runs the docker image. The newly created processs by
docker run
from your py_app
image is called a container
. -d
runs the image as a daemon and print the container id to your console:$ docker run -it -d -p 8085:8084 py_app
d612ffbd9d560158f1c64997f9a8877243cdf4288c11010298df80b10cfaff5e
-p
exposes the port on your docker file to the port on your host machine. The first port 8085
is the port on yourhost, and the second port
8084
is the port on your docker file.Now to see list of your containers use
docker ps
:docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
d612ffbd9d56 py_app "python app.py" 10 minutes ago Up 10 minutes goofy_hopper
From here you can see the ID of your container which is equal to
d612ffbd9d56
. IF you want to have a shell on your container (login into container):
docker exec -it d612ffbd9d56 bash
root@moby:/app#
if you want to connect to the stdout of your container use
attach
, it does not necessary give you a shell:docker attach d612ffbd9d56
*** IF you are attached to a container and press ^c afterward, the container will be stopped.
If you want to stop a container:
$ docker stop d612ffbd9d56
d612ffbd9d56
It prints out container id
d612ffbd9d56
and stop the container. If you enter docker ps
you should not see the container.#docker #commands #docker_part1 #basic #container #devops
What curriculum you are interested in? From now on we will focus more on the specific topics.
Django – 19
👍👍👍👍👍👍👍 58%
Devops (Docker,...) – 7
👍👍👍 21%
Microservice architecture, implementation – 4
👍 12%
Flask – 2
👍 6%
ReactJS – 1
▫️ 3%
👥 33 people voted so far.
Django – 19
👍👍👍👍👍👍👍 58%
Devops (Docker,...) – 7
👍👍👍 21%
Microservice architecture, implementation – 4
👍 12%
Flask – 2
👍 6%
ReactJS – 1
▫️ 3%
👥 33 people voted so far.
I appreciate for the effort you’ve put to incorporate in the poll. As the survey suggests
We would try from the next week to focus more on
We also talk about Docker as a 2nd most voted technology. Don’t worry about it.
As I am a full-time developer I also put other learning materials in the channel too. So be patient. within a month or two you will learn a lot :)
#django #python #docker #podcast #video #toturial
Django
is by far the most voted. We would try from the next week to focus more on
Django
. As many users are at the beginning of the process we’ll try to start from scratch, sorry to say so if you are a senior Django developer :( We also talk about Docker as a 2nd most voted technology. Don’t worry about it.
As I am a full-time developer I also put other learning materials in the channel too. So be patient. within a month or two you will learn a lot :)
BONUS:
we publish videos for some learning materials at the weekend. Thank you all.NOTE:
poll is open. You can still vote.#django #python #docker #podcast #video #toturial
Dear readers,
1st and 2nd part of the basic
1st and 2nd part of the basic
Django
course will be published until 9:00 P.M. ⌚Installation of Django
If you have not yet installed django on your system, install it using the below command:
After installation you can check the validity of the
What does
To see list of
That's it! Welcome to the
#python #django #installation #pip #django_part1
If you have not yet installed django on your system, install it using the below command:
$ sudo pip install django
Password:
Collecting django
Downloading Django-1.11.6-py2.py3-none-any.whl (6.9MB)
100% |████████████████████████████████| 7.0MB 174kB/s
Requirement already satisfied: pytz in /Library/Python/2.7/site-packages (from django)
Installing collected packages: django
Successfully installed django-1.11.6
After installation you can check the validity of the
Django
installation:$ python -m django --version
1.11.6
What does
-m
do in the above command:-m module-name
Searches sys.path for the named module and runs the corresponding .py file as a script.
To see list of
django-admin
subcommands:$ django-admin help
Type 'django-admin help <subcommand>' for help on a specific subcommand.
Available subcommands:
[django]
check
compilemessages
createcachetable
dbshell
diffsettings
dumpdata
flush
inspectdb
loaddata
makemessages
makemigrations
migrate
runserver
sendtestemail
shell
showmigrations
sqlflush
sqlmigrate
sqlsequencereset
squashmigrations
startapp
startproject
test
testserver
Note that only Django core commands are listed as settings are not properly configured (error: Requested setting INSTALLED_APPS, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.)
That's it! Welcome to the
Django
world. :)#python #django #installation #pip #django_part1
Now that you have installed
Tech C**P enough, let's create the project by issuing the below command (project name:
Suppose our project name is
cd into the folder saturn and issue
Now the overall project looks like:
OK let's run our project and see what's in there (you should be in first
If you have a server listening on port 8000, give your port in front of runserver command as below:
There are some warnings (ignore them at the moment), at the end it is said that project is up and running on port 8000. You can see the output in the next post.
#python #django #runserver #startproject #django_part2
Django
successfully you need to start a project. Django
has a command for project administration called django-admin
, by using it you will be able to create a bare-bone project which includes database configuration, Django-specific options and application-specific settings.Tech C**P enough, let's create the project by issuing the below command (project name:
saturn
):$ django-admin startproject saturn
Suppose our project name is
saturn
you can name it everything you like.cd into the folder saturn and issue
ls
, to see list of files created by django-admin
:$ ls
manage.py saturn
NOTE:
do not call your project name django
or test
or anything that is somehow related to keywords, otherwise there will be conflict between your project and django.NOTE:
the project could live every where inside your server, it is not mandatory to put the code in /var/www/
as old PHP does that. It has the risk of exposing your project code to the wild west (Internet). :)Now the overall project looks like:
saturn/
manage.py
saturn/
__init__.py
settings.py
urls.py
wsgi.py
OK let's run our project and see what's in there (you should be in first
saturn
folder):$ python manage.py runserver
Performing system checks...
System check identified no issues (0 silenced).
You have 13 unapplied migration(s). Your project may not work properly until you apply the migrations for app(s): admin, auth, contenttypes, sessions.
Run 'python manage.py migrate' to apply them.
October 27, 2017 - 16:17:10
Django version 1.11.6, using settings 'saturn.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
If you have a server listening on port 8000, give your port in front of runserver command as below:
$ python manage.py runserver 8085
runserver
is a minimal developement-specific server written purely in python
. It reloads itself on code change. In some cases like adding a file does not trigger server reload so you have to restart it manually.There are some warnings (ignore them at the moment), at the end it is said that project is up and running on port 8000. You can see the output in the next post.
NOTE:
some future parts of the project could be in video podcast, it totally depends on your feedbacks and my time.#python #django #runserver #startproject #django_part2
Run a bash in your container:
#docker #exec #bash #container
sudo docker exec -i -t 96885e9e9a51 /bin/bash
96885e9e9a51
is container id. You have to find it yourself by using the below command:docker ps -a
#docker #exec #bash #container
Pass arguments to
If you want to pass multiple arguments to
Now initiate your args inside of
#docker #container #build_arg #argument #build #image
Dockerfile
when you build it using --build-arg
in order to have greater flexibility on docker build:docker build -t essearch/ess-elasticsearch:1.7.6 --build-arg SHARDS_NO=5
If you want to pass multiple arguments to
Dockerfile
give another --build-arg
and give your second argument as above.Now initiate your args inside of
Dockerfile
as below:ARG SHARDS_NO=""
#docker #container #build_arg #argument #build #image
In the last tutorial we designed a project. Project holds the whole infrastructure, it can contain multiple apps. A weblog, an eshop page, poll app could all be an app in our newly created project. The examples are endless.
After project creation to create an app you can use
The structure of the polls app should be as below:
All the poll application logic resides here.
We try first by creating a view that return a sample http response. For writing view for your polls application you have to put it inside of
Yes! That's it. We have created view in django. But for calling this view from outside you have to map a route to it. In my app I don't have the file
The next step is to bind the newly defined route in polls to your project urls route. So for now go to
The first url says that give every route that starts with
Now run your project with the command below and see the result:
The final step is to open your browser and point it to
Voila! Good job everybody :)
If you go to base path you will see the error below (see the picture):
#django #url #include #views #pattern #django_part3
After project creation to create an app you can use
startapp
. For now we create a poll app:$ python manage.py startapp polls
$
The structure of the polls app should be as below:
polls/
__init__.py
admin.py
apps.py
migrations/
__init__.py
models.py
tests.py
views.py
All the poll application logic resides here.
We try first by creating a view that return a sample http response. For writing view for your polls application you have to put it inside of
views.py
:from django.http import HttpResponse
def index(request):
return HttpResponse("Hello, world. You're at the polls index.")
Yes! That's it. We have created view in django. But for calling this view from outside you have to map a route to it. In my app I don't have the file
urls.py
so create it in polls and map as below:from django.conf.urls import url
from . import views
urlpatterns = [
url(r'^$', views.index, name='index'),
]
url
is django module to implement the routing functionality.The next step is to bind the newly defined route in polls to your project urls route. So for now go to
saturn/urls.py
:from django.conf.urls import include, url
from django.contrib import admin
urlpatterns = [
url(r'^polls/', include('polls.urls')),
url(r'^admin/', admin.site.urls),
]
The first url says that give every route that starts with
polls
to polls.urls
. You can see that we have used include
to reference URL configuration. When it reaches /polls
it removes polls
and send the remaining of the URL to polls
.Now run your project with the command below and see the result:
$ python manage.py runserver
The final step is to open your browser and point it to
/polls
and see the result:http://127.0.0.1:8000/polls/
Voila! Good job everybody :)
If you go to base path you will see the error below (see the picture):
#django #url #include #views #pattern #django_part3
To install your python module you need a setup.py file inside of your project. The content of the setup.py can be something like below:
Now if you want to install it on your machine as a package just:
If you want to upload it into your python repository:
NOTE: you should be in the root of your project before running the previous command.
my_repo server should be declared inside of
If you want to install something from your repository via pip you have to provide the
NOTE: you can put inside of an ENV variable in OS to access it better and in more readable way.
#python #setuppy #setup #package #pypi #private_repo #pypirc #pip #install
setup(name=PROJECT_NAME,
version=PROJECT_VERSION,
description=PROJECT_DESCRIPTION,
long_description=PROJECT_LONG_DESCRIPTION,
author='Ali',
author_email='info@ali.com',
url='http://www.ali.com/',
license='SOMETHING',
entry_points=PROJECT_ENTRY_POINTS,
classifiers=[],
keywords='',
packages=find_packages(exclude=['ez_setup', 'examples', 'tests']),
include_package_data=True,
namespace_packages=[],
install_requires=['LIST', 'OF', 'REQUIREMENTS'],
zip_safe=False,
test_suite='nose.collector')
Now if you want to install it on your machine as a package just:
python setup.py install
If you want to upload it into your python repository:
python setup.py sdist upload -r my_repo
NOTE: you should be in the root of your project before running the previous command.
my_repo server should be declared inside of
~/.pypirc
:[distutils]
index-servers =
my_repo
[my_repo]
repository: http://pypi.repo.my_host.com:5000
username: username
password: password
If you want to install something from your repository via pip you have to provide the
extra-index-url
argument:--extra-index-url http://username:password@pypi.repo.my_host.com:5000 --trusted-host pypi.repo.my_host.com
NOTE: you can put inside of an ENV variable in OS to access it better and in more readable way.
#python #setuppy #setup #package #pypi #private_repo #pypirc #pip #install