Skip to main content
adding more content
Source Link

Just for this .. is this all necessary? You could use the flask application , or mapping the each route to a script..

Short answer : No , there are others ways to build what you want that django is not more appropriate.

Long answer

First point

In your methods you are handling the permited methods at hand , the django have the decorators that handle this:

Allowed http methods https://docs.djangoproject.com/en/1.11/topics/http/decorators/#allowed-http-methods

Some methods stayingwould:

@require_http_methods(["GET"])
def list_containers(request):
    pass

@require_http_methods(["GET"])    
def list_images(request):
    pass

@require_http_methods(["GET","POST"])
def networks(request):

    if request.method == "GET":
        # retrieve networks and return them

    if method.method == "POST":
        # create network

urls.py

url(r'container/s', network.list_containers),
url(r'images/', network.list_images),
url(r'networks/', network.networks)

P.s : The views isn't following your structure , but is easily changed.

Second point

The mainly problem with your code is the routes: network/ and network/create to REST definition , the correct would be the route /networks receive the GET and POST and perform different actions ( retrieve and create respectively )

You could use the Django Rest Framework[1] ( the main framework to build restful application in django )

The DRF handle all these: method , routes , views ( viewsets ).

But if django is the bigger to this , you could use the flask framework and use the your routes and the restful frameworks that solves your problem too.

[1] http://www.django-rest-framework.org/

[2] http://flask.pocoo.org/ ( Framework )

[3] https://flask-restful.readthedocs.io/en/0.3.5/ ( FlaskRestful )

Just for this .. is this all necessary? You could use the flask application , or mapping the each route to a script..

Short answer : No , there are others ways to build what you want that django is not more appropriate.

Long answer

First point

In your methods you are handling the permited methods at hand , the django have the decorators that handle this:

Allowed http methods https://docs.djangoproject.com/en/1.11/topics/http/decorators/#allowed-http-methods

Some methods staying:

@require_http_methods(["GET"])
def list_containers():
    pass

@require_http_methods(["GET"])    
def list_images():
    pass

Second point

The mainly problem with your code is the routes: network/ and network/create to REST definition , the correct would be the route /networks receive the GET and POST and perform different actions ( retrieve and create respectively )

You could use the Django Rest Framework[1] ( the main framework to build restful application in django )

The DRF handle all these: method , routes , views ( viewsets ).

But if django is the bigger to this , you could use the flask framework and use the your routes and the restful frameworks that solves your problem too.

[1] http://www.django-rest-framework.org/

[2] http://flask.pocoo.org/ ( Framework )

[3] https://flask-restful.readthedocs.io/en/0.3.5/ ( FlaskRestful )

Just for this .. is this all necessary? You could use the flask application , or mapping the each route to a script..

Short answer : No , there are others ways to build what you want that django is not more appropriate.

Long answer

First point

In your methods you are handling the permited methods at hand , the django have the decorators that handle this:

Allowed http methods https://docs.djangoproject.com/en/1.11/topics/http/decorators/#allowed-http-methods

Some methods would:

@require_http_methods(["GET"])
def list_containers(request):
    pass

@require_http_methods(["GET"])    
def list_images(request):
    pass

@require_http_methods(["GET","POST"])
def networks(request):

    if request.method == "GET":
        # retrieve networks and return them

    if method.method == "POST":
        # create network

urls.py

url(r'container/s', network.list_containers),
url(r'images/', network.list_images),
url(r'networks/', network.networks)

P.s : The views isn't following your structure , but is easily changed.

Second point

The mainly problem with your code is the routes: network/ and network/create to REST definition , the correct would be the route /networks receive the GET and POST and perform different actions ( retrieve and create respectively )

You could use the Django Rest Framework[1] ( the main framework to build restful application in django )

The DRF handle all these: method , routes , views ( viewsets ).

But if django is the bigger to this , you could use the flask framework and use the your routes and the restful frameworks that solves your problem too.

[1] http://www.django-rest-framework.org/

[2] http://flask.pocoo.org/ ( Framework )

[3] https://flask-restful.readthedocs.io/en/0.3.5/ ( FlaskRestful )

Source Link

Just for this .. is this all necessary? You could use the flask application , or mapping the each route to a script..

Short answer : No , there are others ways to build what you want that django is not more appropriate.

Long answer

First point

In your methods you are handling the permited methods at hand , the django have the decorators that handle this:

Allowed http methods https://docs.djangoproject.com/en/1.11/topics/http/decorators/#allowed-http-methods

Some methods staying:

@require_http_methods(["GET"])
def list_containers():
    pass

@require_http_methods(["GET"])    
def list_images():
    pass

Second point

The mainly problem with your code is the routes: network/ and network/create to REST definition , the correct would be the route /networks receive the GET and POST and perform different actions ( retrieve and create respectively )

You could use the Django Rest Framework[1] ( the main framework to build restful application in django )

The DRF handle all these: method , routes , views ( viewsets ).

But if django is the bigger to this , you could use the flask framework and use the your routes and the restful frameworks that solves your problem too.

[1] http://www.django-rest-framework.org/

[2] http://flask.pocoo.org/ ( Framework )

[3] https://flask-restful.readthedocs.io/en/0.3.5/ ( FlaskRestful )