You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Jun 7, 2020. It is now read-only.
Install Django Rest Framework and add it to project
Install and set database to postgresql, add psycopg2 dependency
Split Django settings
Everyone should install Django and django rest framework.
One person (@MartynaAnnaGottschling) runs git init and then push all changes to repository.
The rest of you (@Karrp@maciejSamerdak ) run only git clone https://github.com/Code-Poets/praktyki-2018 when Martyna will finish all these points.
Steps 2, 7, 8 are also required for all.
Implementation
Every single step should be in the separate commit.
Install latest Django using pip.
pip install django
Create new virtualenv based on Python 3.6
Add .gitignore:
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
# C extensions
*.so
# Distribution / packaging
.Python
env/
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
*.egg-info/
.installed.cfg
*.egg
# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec
# Installer logs
pip-log.txt
pip-delete-this-directory.txt
# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*,cover
.hypothesis/
# Translations
*.mo
*.pot
# Django stuff:
*.log
local_settings.py
# Flask stuff:
instance/
.webassets-cache
# Scrapy stuff:
.scrapy
# Sphinx documentation
docs/_build/
# PyBuilder
target/
# IPython Notebook
.ipynb_checkpoints
# pyenv
.python-version
# celery beat schedule file
celerybeat-schedule
# dotenv
.env
# virtualenv
venv/
ENV/
# Spyder project settings
.spyderproject
# Rope project settings
.ropeproject
# Vim's temporary files
*.sw[ponm]
# Local vim settings sourced by the localvimrc plugin
/.lvimrc
# Temporary files created by Windows and OS X
.DS_Store
Thumbs.db
Desktop.ini
# Binary and automatically generated files are not well suited for versioning.
# They should be stored somewhere else and maybe only included in release packges if needed.
# If you're trying to commit one of them you're probably doing something wrong.
*.exe
*.dll
*.msi
*.zip
*.rar
*.tar.gz
*.tar.bz2
*.tar.xz
*.ttf
*.otf
*.pdf
*.doc
*.xls
# Binary database storage
*.sqlite3
Add requirements.txt and requirements.in files.
Use pip freeze > requirements.txt command to add new requirement from your virtualenv.
Copy these requirements to requirements.in without versions.
Do it any time you have to add new requirement to application like Django, pytz or djangorestframework.
Create new Django project using command django-admin startproject <your-project-name>
Install Django Rest Framework and add it to requirements and settings.
Install postgresql on you computer. For Ubuntu use these commands:
There is one thing to do.
Edit with root privileges /etc/postgresql/<version>/main/pg_hba.conf.
Change this line:
local all postgres <method>
Set <method> to trust and restart postgres deamon (for Ubuntu sudo service postgresql restart).
Default method ca be peer or maybe md5.
We have to change that because we want Django to have rights to our database using admin user through local socket.
For more information about pg_hba.conf file: https://www.postgresql.org/docs/9.1/static/auth-pg-hba-conf.html
And remember - to control postgresql service use:
sudo service postgresql start/restart/stop
Create new database:
createdb -U postgres <your_app_name>
If you want to drob database for some reason (ie. recreate it) use:
try:
# local_settings.py is required by the application to work but is not provided by default
# to minimize the risk of someone accidentally running a production site with development settings.
# You need to choose one of the templates (production or development) and rename it to local_settings.py
from .local_settings import * # NOQA # pylint: disable=wildcard-import
except ImportError as exception:
# This condition is not foolproof but should reduce the number of cases where we catch unrelated ImportErrors
if 'local_settings' in str(exception):
raise ImportError("Failed to import 'local_settings' module. Use a production or development template to create one.")
else:
raise
assert 'ENVIRONMENT' in vars(), 'A valid local_settings module should set up ENVIRONMENT setting'
As you can see default settings are always imported. Here we have basic settings and comments about settings that have to be specified in development.py, production.py or local_settings.py.
Development settings are used when we want to test application. They are imported in local_settings.py. This file is actually used for settings and has to be created although it will not be added to git commits due to .gitignore file.
For production we simply use production.py settings.
It is all about our basic settings.
The text was updated successfully, but these errors were encountered:
Overview
.virtualenv
on Python 3.6.gitignore
filerequirements.txt
andrequirements.in
filesEveryone should install Django and django rest framework.
One person (@MartynaAnnaGottschling) runs
git init
and then push all changes to repository.The rest of you (@Karrp @maciejSamerdak ) run only
git clone https://github.com/Code-Poets/praktyki-2018
when Martyna will finish all these points.Steps 2, 7, 8 are also required for all.
Implementation
Every single step should be in the separate commit.
.gitignore
:Add
requirements.txt
andrequirements.in
files.Use
pip freeze > requirements.txt
command to add new requirement from your virtualenv.Copy these requirements to
requirements.in
without versions.Do it any time you have to add new requirement to application like
Django
,pytz
ordjangorestframework
.Create new Django project using command
django-admin startproject <your-project-name>
Install Django Rest Framework and add it to requirements and settings.
Install postgresql on you computer. For Ubuntu use these commands:
There is one thing to do.
Edit with root privileges
/etc/postgresql/<version>/main/pg_hba.conf
.Change this line:
Set
<method>
totrust
and restart postgres deamon (for Ubuntusudo service postgresql restart
).Default method ca be
peer
or maybemd5
.We have to change that because we want Django to have rights to our database using admin user through local socket.
For more information about
pg_hba.conf
file: https://www.postgresql.org/docs/9.1/static/auth-pg-hba-conf.htmlAnd remember - to control postgresql service use:
If you want to drob database for some reason (ie. recreate it) use:
Setting
ATOMIC_REQUESTS
toTrue
gives us assurance that every transaction in database will be atomic. For more informations about Django transactions: https://docs.djangoproject.com/en/2.0/topics/db/transactions/.Copy all your settings to
defaults.py
and remove oldsettings.py
.Then copy these lines to adequate file:
As you can see default settings are always imported. Here we have basic settings and comments about settings that have to be specified in
development.py
,production.py
orlocal_settings.py
.Development settings are used when we want to test application. They are imported in
local_settings.py
. This file is actually used for settings and has to be created although it will not be added to git commits due to.gitignore
file.For production we simply use
production.py
settings.It is all about our basic settings.
The text was updated successfully, but these errors were encountered: