Django application. To launch an api server without endpoint. Create the database on demand.
We can create multiple databases for different applications. Just focusing on the client.
According to how we do the JSON query the server. It will create, alter the table, insert, list or delete data from an entire database automatically.
- Django 1.5+
- django-tokenapi
- valleorm
- django-cors-middleware
First obtain themagicapi package and place it somewhere on your PYTHONPATH, for example
in your project directory (where settings.py is).
Alternatively, if you are using some sort of virtual environment, like virtualenv, you can perform a regular installation or use pip:
python setup.py install
# or ...
pip install django-themagicapi
Add 'themagicapi', 'tokenapi' and 'corsheaders' to your INSTALLED_APPS.
###These are the modifications of settings.py file:
#Add these lines
PATH_DBS = os.path.join(BASE_DIR, "[path-of-databases]/")
MEDIA_ROOT = os.path.join(BASE_DIR, 'docfiles')
MEDIA_URL = '/docfiles/'
INSTALLED_APPS = [
'themagicapi.apps.ThemagicapiConfig',
'corsheaders',
#......
]
MIDDLEWARE = [
'corsheaders.middleware.CorsMiddleware'
#......
]
AUTHENTICATION_BACKENDS = [
'django.contrib.auth.backends.ModelBackend',
'tokenapi.backends.TokenBackend'
#.....
]
CORS_ORIGIN_ALLOW_ALL = TrueInclude themagicapi.urls and tokenapi.urls in your urls.py.
It will look something like this:
urlpatterns = [
url(r'^token/', include('tokenapi.urls')),
url('', include('themagicapi.urls')),
]
You can change the number of days that a token is valid for by setting
TOKEN_TIMEOUT_DAYS in settings.py. The default is 7.
more information see [django-tokenapi]: https://github.com/jpulgarin/django-tokenapi.git
paramsRow = {
'add':{
"db":"valleorm.db",
'user':{
"nombre": "Pepito",
"apellido": "Lopez",
}
}
}
paramsRow = {
'add':{
"db":"valleorm.db",
'user':{
'ID': 1,
'apodo': 'donpepito',
'telf': '666666'
}
}
}
paramsRow = {
'get':{
"db":"valleorm.db",
'user':{
}
}
}
paramsRow = {
'get':{
"db":"valleorm.db",
'user':{
'ID': 1,
}
}
}
paramsRow = {
'rm':{
"db":"valleorm.db",
'user':{
'ID': 1,
}
}
}
For more requests see [themagic-apiserver]: https://github.com/vallemrv/themagic-apiserver.git
import requests
import json
data = json.dumps(***someparams***)
#for get token see https://github.com/jpulgarin/django-tokenapi.git
token = {
'user': 1, #user number
'token': 'some token',
'data': data
}
r = requests.post("http://localhost:8000/", data=token)
print r.json()Licensed under the Apache-2.0, see LICENSE
Manuel Rodriguez [email protected]