{
"info": {
"author": "Jens Becker",
"author_email": "jensbecker@gmail.com",
"bugtrack_url": null,
"classifiers": [
"Development Status :: 3 - Alpha",
"Environment :: Web Environment",
"Framework :: Django",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
"Programming Language :: Python :: 3"
],
"description": "# Inertia.js Django Adapter\n\n> **Warning:** This project is in a very early stage and depends on another early stage library and its frontend adapters called [Inertia.js](https://github.com/inertiajs/inertia).\n\n## Requirements\n\nThis package is meant to be used in a Django application and it uses [django-rest-framework](https://www.django-rest-framework.org/)'s serializers.\n\n```\n$ pipenv install django djangorestframework django-webpack-loader\n```\n\n## Installation\n\nThere is still a few too many manual steps involved using inertia-django. I'm looking for ways (and people to help) to make the initial setup more smooth.\n\nInstall the inertia-django package from [PyPI](https://pypi.org/project/inertia-django/):\n\n```\n$ pipenv install inertia-django\n```\n\n### Webpack \ud83d\udce6\n\n> **INFO:** For now it might be the easiest to take a look or clone the [example repository](https://github.com/jsbeckr/django-inertia-example).\n\nYou have to use webpack for the [Dynamic Imports Feature](https://webpack.js.org/guides/code-splitting/#dynamic-imports). The following config is borrowed from the [Django Inertia.js Example](https://github.com/jsbeckr/django-inertia-example). It uses a few plugins that are not necessary like PurgeCSS, Tailwind, MiniCSSExtract, etc. But the important ones are:\n\n* [Webpack Bundle Tracker](https://github.com/owais/webpack-bundle-tracker) for [Django Webpack Loader](https://github.com/owais/django-webpack-loader).\n* [Vue Loader](https://github.com/vuejs/vue-loader) is optional, but there is only the [inertia-vue](https://github.com/inertiajs/inertia-vue) adapter yet.\n\nwebpack.config.js:\n```javascript\nconst path = require(\"path\");\nconst BundleTracker = require('webpack-bundle-tracker');\nconst VueLoaderPlugin = require('vue-loader/lib/plugin');\nconst CleanWebpackPlugin = require('clean-webpack-plugin');\n\nconst glob = require(\"glob-all\");\nconst MiniCssExtractPlugin = require('mini-css-extract-plugin');\nconst PurgecssPlugin = require(\"purgecss-webpack-plugin\");\n\nclass TailwindExtractor {\n static extract(content) {\n return content.match(/[A-Za-z0-9-_:\\/]+/g) || [];\n }\n}\n\nmodule.exports = {\n mode: 'development',\n devtool: 'inline-source-map',\n // TODO: adjust the entry points to your project\n entry: [\"./core/assets/js/index.js\", \"./core/assets/css/index.postcss\"],\n output: {\n publicPath: \"/static/bundles/\",\n filename: \"[name]-[hash].js\",\n chunkFilename: '[name]-[hash].js',\n path: path.resolve('./bundles/'),\n },\n\n plugins: [\n new BundleTracker({ filename: './webpack-stats.json' }),\n new VueLoaderPlugin(),\n new CleanWebpackPlugin(),\n new MiniCssExtractPlugin({\n filename: \"[name]-[hash].css\"\n }),\n new PurgecssPlugin({\n paths: glob.sync([\n // TODO: adjust the directories to your project\n path.join(__dirname, \"core/assets/js/**/*.vue\"),\n path.join(__dirname, \"core/templates/index.html\")\n ]),\n extractors: [\n {\n extractor: TailwindExtractor,\n extensions: [\"html\", \"js\", \"vue\"]\n }\n ]\n })\n ],\n\n module: {\n rules: [\n {\n test: /\\.m?js$/,\n exclude: /(node_modules|bower_components)/,\n use: {\n loader: 'babel-loader',\n options: {\n presets: [\n '@babel/preset-env'\n ],\n plugins: [\"@babel/plugin-syntax-dynamic-import\"]\n }\n }\n },\n {\n test: /\\.vue$/,\n use: 'vue-loader'\n },\n {\n test: /\\.postcss$/,\n use: [\n {\n loader: MiniCssExtractPlugin.loader,\n },\n { loader: 'css-loader', options: { importLoaders: 1 } },\n 'postcss-loader',\n\n ]\n }\n ]\n },\n\n resolve: {\n extensions: ['.js', '.vue'],\n alias: {\n 'vue$': 'vue/dist/vue.runtime.js',\n // TODO: adjust or remove, it's a convenient way to import js files in your components\n '@': path.resolve('core/assets/js'),\n }\n },\n}\n```\n\n\n## Usage\n\n\n\n### `render_inertia` function\n\nThe easiest way to render a Vue component with inertia-django is to use the `render_inertia` function. *Note:* You have to have an `Index.vue` component in your project.\n\n```python\nfrom inertia import render_inertia\n\ndef index(request):\n # for function views just use the render_inertia function\n return render_inertia(request, 'Index', props={'title': 'My inertia-django page'}, template_name='index.html')\n```\n\nThis would be a bit much to write everytime so you can omit the `template_name` and set it in settings.py:\n\n```python\nINERTIA_TEMPLATE = 'index.html'\n```\n\nAfter that you just have to call:\n\n```python\nfrom inertia import render_inertia\n\ndef index(request):\n # for function views just use the render_inertia function\n return render_inertia(request, 'Index', props={'title': 'My inertia-django page'})\n```\n\n### `InertiaListView`\n\ninertia-django ships with a crude implementations of the generic [ListView](https://docs.djangoproject.com/en/2.2/ref/class-based-views/generic-display/#listview):\n\nviews.py:\n```python\nclass Index(InertiaListView):\n # Inertia supports List and DetailViews right now\n model = Contact\n serializer_class = ContactSerializer\n component_name = \"Index\"\n```\n\nIndex.vue\n```vue\n\n \n
Contacts
\n
User: {{shared.user.username}}
\n
\n
\n \n {{contact.name}}\n \n
\n
\n \n\n\n\n```\n\n### `InertiaDetailView`\n\ninertia-django ships with a crude implementations of the generic [DetailView](https://docs.djangoproject.com/en/2.2/ref/class-based-views/generic-display/#detailview):\n\nviews.py:\n```python\nclass ContactView(InertiaDetailView):\n model = Contact\n serializer_class = ContactSerializer\n component_name = \"Contact\"\n props = {\"test\": True} # you can inject any props you want\n```\n\nContact.vue:\n```vue\n\n \n Home\n
{{contact.name}}, {{contact.first_name}}
\n
Age: {{contact.age}}
\n
Test: {{test}}
\n \n\n\n\n```\n\n### `inertia.share` function\n\nIf you want to have some basic props that are always injected, you can `share` them between Components:\n\n> I had to declare the `UserSerializer` in apps.py so that it is available at startup. If somebody has a better idea feel free to create an issue.\n\ne.g. apps.py:\n```python\nfrom django.apps import AppConfig\nfrom django.contrib.auth import get_user, get_user_model\nfrom rest_framework import serializers\nfrom inertia import share\n\n\ndef current_user(request):\n class UserSerializer(serializers.ModelSerializer):\n\n class Meta:\n model = get_user_model()\n fields = [\"username\", \"email\"]\n\n return UserSerializer(get_user(request)).data\n\n\nclass CoreConfig(AppConfig):\n name = 'core'\n\n def ready(self):\n share('title', 'Django Inertia.js Example \ud83e\udd18')\n share('user', current_user)\n```\n\nAs you might have recognized `current_user` is a function. While rendering inertia-django checks if a shared property is callable and if it is, it will call that function with the current request.\n\n## Example\n\n~~Take a look at [this repository](https://github.com/jsbeckr/django-inertia-example) for an example of how to use this package.~~\n\n\n",
"description_content_type": "text/markdown",
"docs_url": null,
"download_url": "",
"downloads": {
"last_day": -1,
"last_month": -1,
"last_week": -1
},
"home_page": "https://github.com/jsbeckr/inertia-django",
"keywords": "django inertia template",
"license": "",
"maintainer": "",
"maintainer_email": "",
"name": "inertia-django",
"package_url": "https://pypi.org/project/inertia-django/",
"platform": "",
"project_url": "https://pypi.org/project/inertia-django/",
"project_urls": {
"Homepage": "https://github.com/jsbeckr/inertia-django"
},
"release_url": "https://pypi.org/project/inertia-django/0.1.1/",
"requires_dist": null,
"requires_python": ">=3.2",
"summary": "The Django adapter for Inertia.js.",
"version": "0.1.1"
},
"last_serial": 5161814,
"releases": {
"0.1.0": [
{
"comment_text": "",
"digests": {
"md5": "504d5d11ec9d5cc8e0ff790be4886464",
"sha256": "d0e5b559636e5ffed529b1d950afe0881e42204be9fb18e90475a4975bf9b6e0"
},
"downloads": -1,
"filename": "inertia_django-0.1.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "504d5d11ec9d5cc8e0ff790be4886464",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.2",
"size": 3991,
"upload_time": "2019-04-06T18:44:23",
"url": "https://files.pythonhosted.org/packages/10/14/3f27f97909a3fe13e49fa688da7e8c483bd3e76c2a5913daf514e4daa46f/inertia_django-0.1.0-py3-none-any.whl"
},
{
"comment_text": "",
"digests": {
"md5": "a0324dea47addaebd63f436b17d4e8a8",
"sha256": "a19c3733085b01c6c6ae517b167b04da3c7523cd16c06e3303c62459c830c897"
},
"downloads": -1,
"filename": "inertia-django-0.1.0.tar.gz",
"has_sig": false,
"md5_digest": "a0324dea47addaebd63f436b17d4e8a8",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.2",
"size": 2526,
"upload_time": "2019-04-06T18:44:25",
"url": "https://files.pythonhosted.org/packages/b4/3a/131157af31477a98e7583ca66c468c1a776b691efbcbedd092cba8b331fa/inertia-django-0.1.0.tar.gz"
}
],
"0.1.1": [
{
"comment_text": "",
"digests": {
"md5": "ebf173984e9cdeeef67c9c4b13302b90",
"sha256": "acd3b65959c1f7eef89daaf066554883171675b3dcb8d8852d1df2c1d230c7e2"
},
"downloads": -1,
"filename": "inertia_django-0.1.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "ebf173984e9cdeeef67c9c4b13302b90",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.2",
"size": 7028,
"upload_time": "2019-04-18T19:31:03",
"url": "https://files.pythonhosted.org/packages/0a/e8/5917cede7a6cf9e87d448cb3b749ff31d6bdf600c6c575b64ca4fc76091a/inertia_django-0.1.1-py3-none-any.whl"
},
{
"comment_text": "",
"digests": {
"md5": "223dfa6c436c16273a0947a92dfc0dd1",
"sha256": "3c562db7b984fe45bc61ace92f4892f23bf3e83fd0608a7bbd4727d9e6c108b2"
},
"downloads": -1,
"filename": "inertia-django-0.1.1.tar.gz",
"has_sig": false,
"md5_digest": "223dfa6c436c16273a0947a92dfc0dd1",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.2",
"size": 6091,
"upload_time": "2019-04-18T19:31:05",
"url": "https://files.pythonhosted.org/packages/37/31/576813b367b6d16dde9a03ab9a0e7594fdfc0a429bcbacacd3ad583d8048/inertia-django-0.1.1.tar.gz"
}
]
},
"urls": [
{
"comment_text": "",
"digests": {
"md5": "ebf173984e9cdeeef67c9c4b13302b90",
"sha256": "acd3b65959c1f7eef89daaf066554883171675b3dcb8d8852d1df2c1d230c7e2"
},
"downloads": -1,
"filename": "inertia_django-0.1.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "ebf173984e9cdeeef67c9c4b13302b90",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.2",
"size": 7028,
"upload_time": "2019-04-18T19:31:03",
"url": "https://files.pythonhosted.org/packages/0a/e8/5917cede7a6cf9e87d448cb3b749ff31d6bdf600c6c575b64ca4fc76091a/inertia_django-0.1.1-py3-none-any.whl"
},
{
"comment_text": "",
"digests": {
"md5": "223dfa6c436c16273a0947a92dfc0dd1",
"sha256": "3c562db7b984fe45bc61ace92f4892f23bf3e83fd0608a7bbd4727d9e6c108b2"
},
"downloads": -1,
"filename": "inertia-django-0.1.1.tar.gz",
"has_sig": false,
"md5_digest": "223dfa6c436c16273a0947a92dfc0dd1",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.2",
"size": 6091,
"upload_time": "2019-04-18T19:31:05",
"url": "https://files.pythonhosted.org/packages/37/31/576813b367b6d16dde9a03ab9a0e7594fdfc0a429bcbacacd3ad583d8048/inertia-django-0.1.1.tar.gz"
}
]
}