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
In this session we'll have a brief look at the
To setup your database you need to give the credential in saturn/settings.py in the section:
As you see above the default database is set to
If you are using a db other than sqlite like
our project. For example for session management there is
Some of these applications use database tables, so for Django apps to work properly, youn need to use
and create corresponding tables:
You can see that needed tables are created as above. In case you don't need an app just comment it out from
The next session we would create models for our tables and would do the real parts. :)
#python #django #settings #INSTALLED_APPS #migration #database #ENGINE #django_part4
settings.py
file and do a migration for the saturn
project.To setup your database you need to give the credential in saturn/settings.py in the section:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
As you see above the default database is set to
sqlite3
and the NAME
of the database is set to file path of db.sqlite3
, if your database is set to MySQL you would have to provide the name of the database in NAME
section.ENGINE
can have one of the below database bindings:'django.db.backends.sqlite3',
'django.db.backends.postgresql',
'django.db.backends.mysql',
'django.db.backends.oracle'
If you are using a db other than sqlite like
MySQL
you should provide USER
, PASSWORD
HOST
beside ENGINE
and NAME
.INSTALLED_APPS
is a section that contains apps used by our project. For example for session management there is
django.contrib.sessions
section.Some of these applications use database tables, so for Django apps to work properly, youn need to use
migrate
commandand create corresponding tables:
$ python manage.py migrate
Operations to perform:
Apply all migrations: admin, auth, contenttypes, sessions
Running migrations:
Applying contenttypes.0001_initial... OK
Applying auth.0001_initial... OK
Applying admin.0001_initial... OK
Applying admin.0002_logentry_remove_auto_add... OK
Applying contenttypes.0002_remove_content_type_name... OK
Applying auth.0002_alter_permission_name_max_length... OK
Applying auth.0003_alter_user_email_max_length... OK
Applying auth.0004_alter_user_username_opts... OK
Applying auth.0005_alter_user_last_login_null... OK
Applying auth.0006_require_contenttypes_0002... OK
Applying auth.0007_alter_validators_add_error_messages... OK
Applying auth.0008_alter_user_username_max_length... OK
Applying sessions.0001_initial... OK
You can see that needed tables are created as above. In case you don't need an app just comment it out from
INSTALLED_APPS
before running migration.The next session we would create models for our tables and would do the real parts. :)
#python #django #settings #INSTALLED_APPS #migration #database #ENGINE #django_part4
Install a specific version of
https://askubuntu.com/questions/957439/how-to-install-a-specific-version-of-node-on-ubuntu-server
#ubuntu #linux #nodejs #node #versioin #installation
NODEJS
on linux server:https://askubuntu.com/questions/957439/how-to-install-a-specific-version-of-node-on-ubuntu-server
#ubuntu #linux #nodejs #node #versioin #installation
Ask Ubuntu
How to install a Specific Version of Node on Ubuntu Server
I am trying to install Node 6.11.3 on my Ubuntu Server.
I don't want to use nvm for this.
I have already used this link but it just does not work out while using jenkins and stuff.
I want to
I don't want to use nvm for this.
I have already used this link but it just does not work out while using jenkins and stuff.
I want to
Install NPM packages from
Sometimes because of filtering issues you need to download node packages from http so make sure to make it http:
#node #npm #shit #installation #config
http
or https
:npm config set registry https://registry.npmjs.org/
Sometimes because of filtering issues you need to download node packages from http so make sure to make it http:
npm config set registry http://registry.npmjs.org/
#node #npm #shit #installation #config
If you have Mac system and created bash scripts so far, there is a fun feature on OS X that you can type
Or let's say you have a bash script that will take a lot of time and at the end of the script your want to hear
#osx #say #command #fun
say
command. say
will say the phrase:say hello channel users
Or let's say you have a bash script that will take a lot of time and at the end of the script your want to hear
operation done successfully
from your speaker:say operation done successfully
#osx #say #command #fun
There is a command in osX called
The great thing about this command is that you can open finder when you have traversed a long path and now you want it to have inside of finder. Go to the desired directory in your terminal using
it will open you finder. :)
#osx #open #command #fun #trick
open
that will open finder for you from within of your terminal.The great thing about this command is that you can open finder when you have traversed a long path and now you want it to have inside of finder. Go to the desired directory in your terminal using
cd
then use:open .
it will open you finder. :)
#osx #open #command #fun #trick