{ "info": { "author": "Max Poletaev", "author_email": "max.poletaev@gmail.com", "bugtrack_url": null, "classifiers": [ "Framework :: Django", "Framework :: Django :: 2.0", "Programming Language :: Python", "Programming Language :: Python :: 3.4", "Programming Language :: Python :: 3.5", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7" ], "description": "============\nDjango Micro\n============\n\n.. image::\n https://img.shields.io/pypi/v/django-micro.svg\n :target: https://pypi.python.org/pypi/django-micro\n\n.. image::\n https://img.shields.io/badge/status-stable-brightgreen.svg\n\nDjango Micro is lightweight wrapper around Django that turns it to the microframework for writing small applications in a single file.\n\n**tl;dr:** See the example_ of full-featured application.\n\n\nWhat works\n==========\n\n- `Configuration`_\n- `Views and routes`_\n- `Models and migrations`_\n- `Management commands`_\n- `Custom template tags`_\n- `Testing`_\n- `Admin interface`_\n- Third party apps\n\n\nInstallation\n============\n\n.. code-block::\n\n $ pip install django-micro\n\n\nQuick start\n===========\n\nCreate ``app.py`` file with following content.\n\n.. code-block:: python\n\n from django_micro import configure, route, run\n from django.http import HttpResponse\n\n DEBUG = True\n configure(locals())\n\n\n @route('', name='homepage')\n def homepage(request):\n name = request.GET.get('name', 'World')\n return HttpResponse('Hello, {}!'.format(name))\n\n\n application = run()\n\nRun the application.\n\n.. code-block::\n\n $ python app.py runserver\n\n**Note:** Parent directory of the ``app.py`` file must have a valid python module name. Under the hood, Micro adds that directory to ``INSTALLED_APPS`` and uses it as a regular Django application.\n\n\nCompatibility\n=============\n\nThe latest relase of django-micro supports only the latest stable release of Django. This is the only way to keep codebase of django-micro clean, without hacks for different versions of Django.\n\n- **Django version:** >=2.0, <2.1\n- **Python version:** >=3.4\n\n\nRun and deployment\n==================\n\nOn the localhost the application runs with the built-in ``runserver`` command and deploys as a standard WSGI application.\n\n.. code-block::\n\n $ python app.py runserver\n $ gunicorn example.app --bind localhost:8000\n $ uwsgi --module example.app --http localhost:8000\n\nThis behaviour is provided by the single string: ``application = run()`` which actually just a shortcut for the following code.\n\n.. code-block:: python\n\n if __name__ == '__main__':\n from django.core.management import execute_from_command_line\n execute_from_command_line(sys.argv)\n else:\n from django.core.wsgi import get_wsgi_application\n application = get_wsgi_application()\n\n\nConfiguration\n=============\n\nThe call of the ``configure`` function must be placed at the top of your application above the definition of views, models, and imports of other modules. It may violate PEP8, but this is the only way to make it works. You can\u2019t define models or import models from another application until Django is configured.\n\nI recommend to define all the configuration in the global namespace and call ``configure`` with ``locals()`` argument. Don\u2019t worry, configure takes only *UPPERCASE* variables.\n\n.. code-block:: python\n\n from django_micro import configure\n\n DEBUG = True\n\n configure(locals())\n\n\nViews and routes\n================\n\nRouting is wrapped in a single function ``route``. You can use it as a decorator.\n\n.. code-block:: python\n\n from django_micro import route\n\n @route('blog//', name='year_archive')\n def year_archive(request, year):\n return HttpResponse('hello')\n\nOr as a regular function.\n\n.. code-block:: python\n\n def year_archive(request):\n return HttpResponse('hello')\n\n route('blog//', year_archive, name='year_archive')\n\nAlso ``route`` may be used with class-based views.\n\n.. code-block:: python\n\n @route('blog//', name='year_archive')\n class YearArchiveView(View):\n def get(request, year):\n return HttpResponse('hello')\n\n # or directly\n route('blog//', YearArchiveView.as_view(), name='year_archive')\n\nMicro uses the new simplified routing syntax which was introduced in Django 2.0. But if you\u2019d like to use the regex-based routing syntax, just add ``regex=True`` to the decorator.\n\n.. code-block:: python\n\n @route(r'^articles/(?P[0-9]{4})/$', regex=True)\n def year_archive(request, year):\n return HttpResponse('hello')\n\nYou always can access the ``urlpatterns`` for the use low-level API.\n\n.. code-block:: python\n\n from django.urls import path\n import django_micro as micro\n\n micro.urlpatterns += [\n path('', homepage, name='homepage'),\n ]\n\n\n**Note:** You can include third-party apps into Micro\u2019s ``urlpatterns``, but currently can\u2019t use Micro as a third-party app. Micro is a singleton, and you can\u2019t create more that one instance of it.\n\n\nModels and migrations\n=====================\n\nMicro works well with models and migrations. Just define model in your ``app.py`` file. If you need migrations, create ``migrations`` directory next to the ``app.py`` and call ``python app.py makemigrations``.\n\n.. code-block::\n\n blog\n \u251c\u2500\u2500 __init__.py\n \u251c\u2500\u2500 app.py\n \u2514\u2500\u2500 migrations\n \u251c\u2500\u2500 __init__.py\n \u2514\u2500\u2500 0001_initial.py\n\n.. code-block:: python\n\n from django.db import models\n\n class Post(models.Model):\n title = models.CharField(max_length=255)\n\n class Meta:\n app_label = 'blog'\n\n**Note:** You always need to set ``app_label`` attribute in ``Meta`` of your models. For example, if application placed in ``blog/app.py``, app_label should be ``blog``.\n\nFor getting ``app_label`` you can use ``get_app_label`` shortcut.\n\n.. code-block:: python\n\n from django_micro import get_app_label\n\n class Meta:\n app_label = get_app_label()\n\nYou also can place models separately in ``models.py`` file. In this case ``app_label`` is not required, but this is not a micro-way ;)\n\n\nManagement commands\n===================\n\nNow you can create any management command without creating a file in ``yourapp/management/commands``. Just defne command class in your ``app.py`` and wrap it to ``@command`` decorator.\n\n.. code-block:: python\n\n from django.core.management.base import BaseCommand\n from django_micro import command\n\n @command('print_hello')\n class PrintHelloCommand(BaseCommand):\n def handle(self, *args, **options):\n self.stdout.write('Hello, Django!')\n\nYou also can create function-based commands.\n\n.. code-block:: python\n\n from django_micro import command\n\n @command\n def print_hello(cmd, **options):\n cmd.stdout.write('Hello, Django!')\n\nUnfortunately, the ``command`` decorator uses a few dirty hacks for command registration. But everything works fine if you don\u2019t think about it ;)\n\n\nCustom template tags\n====================\n\nUse ``template`` for register template tags. It works same as a ``register`` object in tag library file.\n\n.. code-block:: python\n\n from django_micro import template\n\n @template.simple_tag\n def print_hello(name):\n return 'Hello, {}!'\n\n @template.filter\n def remove_spaces(value):\n return value.replace(' ', '')\n\n\nYou don\u2019t need to use the ``load`` tag. All template tags are global.\n\n\nTesting\n=======\n\nNo magick. Use built-in test cases.\n\n.. code-block:: python\n\n from django.test import TestCase\n\n class TestIndexView(TestCase):\n def test_success(self):\n response = self.client.get('/')\n self.assertEqual(response.status_code, 200)\n\nTo run tests which defined in app.py use the following command:\n\n.. code-block::\n\n $ python app.py test __main__\n\n\nAdmin interface\n===============\n\nDjango-admin requires lots of dependencies in apps and middlewares. We\u2019ve realized that it\u2019s not a simple way to add a huge list of apps to your config just to use the admin interface. So we added a shortcut ``django_admin=True`` to the ``configure`` function that automatically includes all the needed dependencies.\n\n.. code-block:: python\n\n from django.contrib import admin\n from django_micro import configure\n\n configure(locals(), django_admin=True)\n\n\n class Post(models.Model):\n title = models.CharField(max_length=255)\n content = models.TextField(blank=True)\n create_date = models.DateTimeField(auto_now_add=True)\n\n class Meta:\n app_label = get_app_label()\n ordering = ('-create_date',)\n\n\n @admin.register(Post)\n class PostAdmin(admin.ModelAdmin):\n pass\n\n\n route('admin/', admin.site.urls)\n\n\nWho uses django-micro\n=====================\n\n- `storagl `_ \u2014 simple storage for screenshots and other shared files with short direct links\n\n\nRelated projects\n================\n\n- importd_ \u2014\u00a0Popular implementation of django-as-microframework idea, but too magical and over-engineered in my opinion.\n\n- djmicro_ \u2014 Good and lightweight wrapper. I\u2019ve took a few ideas from there. But it\u2019s an experimental, undocumented and doesn\u2019t develop anymore.\n\n\n.. _example: https://github.com/zenwalker/django-micro/tree/master/example\n.. _djmicro: https://github.com/apendleton/djmicro\n.. _importd: https://github.com/amitu/importd\n", "description_content_type": "", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/zenwalker/django-micro", "keywords": "django microframework", "license": "BSD", "maintainer": "", "maintainer_email": "", "name": "django-micro", "package_url": "https://pypi.org/project/django-micro/", "platform": "", "project_url": "https://pypi.org/project/django-micro/", "project_urls": { "Homepage": "https://github.com/zenwalker/django-micro" }, "release_url": "https://pypi.org/project/django-micro/1.8.0/", "requires_dist": null, "requires_python": "", "summary": "Django as a microframework", "version": "1.8.0" }, "last_serial": 5967203, "releases": { "1.0.0": [ { "comment_text": "", "digests": { "md5": "83a7186e23922df530cd5e6e5032a6f0", "sha256": "71c1a4c47ca45a8ca8d619cdee7951ffb58f60a4a3c7813536dc426a5b930fee" }, "downloads": -1, "filename": "django-micro-1.0.0.tar.gz", "has_sig": false, "md5_digest": "83a7186e23922df530cd5e6e5032a6f0", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 2512, "upload_time": "2016-09-29T22:00:10", "url": "https://files.pythonhosted.org/packages/c0/e7/989331dafb50808d687e6f865373f5981f703c3e29df20f846b2ac7ffb9c/django-micro-1.0.0.tar.gz" } ], "1.1.0": [ { "comment_text": "", "digests": { "md5": "cb920a1ff51442bb649a401c61010bcd", "sha256": "f817a24b23efdc597b2493f7619e3f59426c2e7b0687c897ede5677166209c9c" }, "downloads": -1, "filename": "django-micro-1.1.0.tar.gz", "has_sig": false, "md5_digest": "cb920a1ff51442bb649a401c61010bcd", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4199, "upload_time": "2016-10-01T11:34:50", "url": "https://files.pythonhosted.org/packages/8e/c1/4cfe82b9007b3635c0b156c750f7beff4fcb7988844076e78b884d8f5737/django-micro-1.1.0.tar.gz" } ], "1.1.1": [ { "comment_text": "", "digests": { "md5": "63b747135731a76a03fa8550952800fc", "sha256": "46f7b380328798ab3b880f6eb8ef62d37de435587f4042465329abf73b0a3ae6" }, "downloads": -1, "filename": "django-micro-1.1.1.tar.gz", "has_sig": false, "md5_digest": "63b747135731a76a03fa8550952800fc", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4410, "upload_time": "2016-10-05T19:17:03", "url": "https://files.pythonhosted.org/packages/95/57/7583d123e4239134bd2f2a65ec973fc03ba713256b6c29c6a5e4807c616a/django-micro-1.1.1.tar.gz" } ], "1.2.0": [ { "comment_text": "", "digests": { "md5": "5e3e28ebf8f6ebd5929b5629a61f1bb6", "sha256": "db230993eb93dbc0df500a739584a9dfb6c6f056ccf72f0e3d114bf7094f8b63" }, "downloads": -1, "filename": "django-micro-1.2.0.tar.gz", "has_sig": false, "md5_digest": "5e3e28ebf8f6ebd5929b5629a61f1bb6", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4533, "upload_time": "2016-10-08T16:08:06", "url": "https://files.pythonhosted.org/packages/1a/2a/775fa4ec9190f157d811af1819be351636f78cc20b9a3df19a411c41d98e/django-micro-1.2.0.tar.gz" } ], "1.3.0": [ { "comment_text": "", "digests": { "md5": "6f4cdf39800ec0a11bf7cc698d1c025e", "sha256": "3e2f4a13a8831bfd607f2ac762a320aeb112a5bc6ac8eb15f51c2438e3bc3aa3" }, "downloads": -1, "filename": "django-micro-1.3.0.tar.gz", "has_sig": false, "md5_digest": "6f4cdf39800ec0a11bf7cc698d1c025e", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4829, "upload_time": "2016-10-17T18:37:29", "url": "https://files.pythonhosted.org/packages/19/a2/cc77ac5fe5391c1785f50bb1c9526d430a0c0698fdc5ff7cab7120498f01/django-micro-1.3.0.tar.gz" } ], "1.4.0": [ { "comment_text": "", "digests": { "md5": "9cc16f120da740366b621dd817ea640e", "sha256": "f83c40180362c048a6057f387a9e3225c07efac204e7e3d202fef70115fc6b9f" }, "downloads": -1, "filename": "django-micro-1.4.0.tar.gz", "has_sig": false, "md5_digest": "9cc16f120da740366b621dd817ea640e", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5180, "upload_time": "2017-03-05T07:51:23", "url": "https://files.pythonhosted.org/packages/65/4d/fea99843cfc379123869cbcd0eb484fc30a7c2832af77fad393de413f215/django-micro-1.4.0.tar.gz" } ], "1.4.1": [ { "comment_text": "", "digests": { "md5": "bf7ed5c400acc720bd7414d6c57b614e", "sha256": "df4cd98dad23db9d9ab649f815855ba32086a48e85fdcc8b366ecf627c8e8b41" }, "downloads": -1, "filename": "django-micro-1.4.1.tar.gz", "has_sig": false, "md5_digest": "bf7ed5c400acc720bd7414d6c57b614e", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5179, "upload_time": "2017-03-08T08:19:47", "url": "https://files.pythonhosted.org/packages/cc/6c/78f99e2977594e7afc04fe4d41069ce123ea395f3ae327fd46ba856e7d37/django-micro-1.4.1.tar.gz" } ], "1.4.2": [ { "comment_text": "", "digests": { "md5": "d4da39f8bf7ca45447673d2f79454c01", "sha256": "d2e5854ecb37070633d3d404a1fca25ceb3fa3d7830c68206bba3b9192d9487a" }, "downloads": -1, "filename": "django-micro-1.4.2.tar.gz", "has_sig": false, "md5_digest": "d4da39f8bf7ca45447673d2f79454c01", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5165, "upload_time": "2017-04-05T18:32:18", "url": "https://files.pythonhosted.org/packages/7e/ee/b8fa4345ebf94970534ab5e9470bf734983eafa90d6623c193e037bf14f0/django-micro-1.4.2.tar.gz" } ], "1.5": [ { "comment_text": "", "digests": { "md5": "e9e36db96d639f8850b57e26f42c680e", "sha256": "ad09958a8e7a7412831b964fb32ce982304e74ffb31f77c114b5e2feca8abeb4" }, "downloads": -1, "filename": "django-micro-1.5.tar.gz", "has_sig": false, "md5_digest": "e9e36db96d639f8850b57e26f42c680e", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5399, "upload_time": "2017-12-04T13:10:05", "url": "https://files.pythonhosted.org/packages/ad/9c/ce1272f1302ef4b9aec060d2ad77db2bc40608edd2294004179e6aac2155/django-micro-1.5.tar.gz" } ], "1.6.0": [ { "comment_text": "", "digests": { "md5": "15c0e605d8d29a395c0fd6d4b36ccd97", "sha256": "76ccace107a7c87db6c1325630c11f2aafb1ffb5c5cdcb9597e48cb460223ea4" }, "downloads": -1, "filename": "django-micro-1.6.0.tar.gz", "has_sig": false, "md5_digest": "15c0e605d8d29a395c0fd6d4b36ccd97", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5878, "upload_time": "2018-02-11T12:49:24", "url": "https://files.pythonhosted.org/packages/29/37/383db126c0ef45dbf4adc906fa6dffdd86ad7c9b1437805cae91672996d2/django-micro-1.6.0.tar.gz" } ], "1.6.1": [ { "comment_text": "", "digests": { "md5": "afe82e2865fcd3107925df2790a68151", "sha256": "92ff424585d565180a0302bba459a7e47258ac86313ea411d54487642125649f" }, "downloads": -1, "filename": "django-micro-1.6.1.tar.gz", "has_sig": false, "md5_digest": "afe82e2865fcd3107925df2790a68151", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5903, "upload_time": "2018-02-20T08:13:52", "url": "https://files.pythonhosted.org/packages/3e/24/81eac5e77c4070ecb1da6d382005f730069d096a92381e3537bf5ae06336/django-micro-1.6.1.tar.gz" } ], "1.7.1": [ { "comment_text": "", "digests": { "md5": "02d69e48bae1062601b6e921327aa40b", "sha256": "ad5c5be125110a650131bc1d3872903a80f2d7da6b2a8f916caf418a0fe004e9" }, "downloads": -1, "filename": "django-micro-1.7.1.tar.gz", "has_sig": false, "md5_digest": "02d69e48bae1062601b6e921327aa40b", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6897, "upload_time": "2018-06-30T20:29:46", "url": "https://files.pythonhosted.org/packages/83/f1/5b3ed73c89b1f83de67f125b75f65d204f49850401f7dd7497c9957f8ce8/django-micro-1.7.1.tar.gz" } ], "1.7.2": [ { "comment_text": "", "digests": { "md5": "1572c986c8cae5eafe0b70ace729b482", "sha256": "be0f508d0b9bd4c6b68e789ccd653d4fe390c9aa0c1d8ab4b51cba0b5d679427" }, "downloads": -1, "filename": "django-micro-1.7.2.tar.gz", "has_sig": false, "md5_digest": "1572c986c8cae5eafe0b70ace729b482", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6912, "upload_time": "2018-08-28T20:05:43", "url": "https://files.pythonhosted.org/packages/25/2f/d2fddbf023a743684a8e1e9d75916d7f73571daf55c77a38aac14a073c92/django-micro-1.7.2.tar.gz" } ], "1.7.3": [ { "comment_text": "", "digests": { "md5": "803f4f926c9b081173d307b51f271b1a", "sha256": "0a7a433ab12aed5df184dce100316f7d6bb2fe29faf28b2acda4c964394fa6a7" }, "downloads": -1, "filename": "django-micro-1.7.3.tar.gz", "has_sig": false, "md5_digest": "803f4f926c9b081173d307b51f271b1a", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6917, "upload_time": "2019-07-06T14:31:34", "url": "https://files.pythonhosted.org/packages/7e/ac/1a46a24af5806910f4eb055587db87d66fb7995e7a8515c90eb7c861ebc5/django-micro-1.7.3.tar.gz" } ], "1.8.0": [ { "comment_text": "", "digests": { "md5": "105c46ca9dbcdd3bfe860a3023ba2174", "sha256": "580424c910ca474f2157b7fc9719042c95a903afc1c2e32ac2af23535a125f24" }, "downloads": -1, "filename": "django-micro-1.8.0.tar.gz", "has_sig": false, "md5_digest": "105c46ca9dbcdd3bfe860a3023ba2174", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6941, "upload_time": "2019-10-13T12:06:10", "url": "https://files.pythonhosted.org/packages/2d/60/c219efb967a512b48080013f24310a72d7d2f209f163981d057cccc2dbe0/django-micro-1.8.0.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "105c46ca9dbcdd3bfe860a3023ba2174", "sha256": "580424c910ca474f2157b7fc9719042c95a903afc1c2e32ac2af23535a125f24" }, "downloads": -1, "filename": "django-micro-1.8.0.tar.gz", "has_sig": false, "md5_digest": "105c46ca9dbcdd3bfe860a3023ba2174", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6941, "upload_time": "2019-10-13T12:06:10", "url": "https://files.pythonhosted.org/packages/2d/60/c219efb967a512b48080013f24310a72d7d2f209f163981d057cccc2dbe0/django-micro-1.8.0.tar.gz" } ] }