{"id":46238300,"url":"https://github.com/tmpbook/django-with-vuejs","last_synced_at":"2026-03-03T19:34:01.359Z","repository":{"id":17164090,"uuid":"80927573","full_name":"tmpbook/django-with-vuejs","owner":"tmpbook","description":"Fast and clear in DevOps.","archived":false,"fork":false,"pushed_at":"2022-12-07T17:19:38.000Z","size":1650,"stargazers_count":422,"open_issues_count":27,"forks_count":109,"subscribers_count":25,"default_branch":"master","last_synced_at":"2024-04-15T11:39:31.605Z","etag":null,"topics":["devops","django","vuejs"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tmpbook.png","metadata":{"files":{"readme":"README-zh.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-02-04T15:18:57.000Z","updated_at":"2024-03-04T13:41:22.000Z","dependencies_parsed_at":"2023-01-11T20:26:01.108Z","dependency_job_id":null,"html_url":"https://github.com/tmpbook/django-with-vuejs","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/tmpbook/django-with-vuejs","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tmpbook%2Fdjango-with-vuejs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tmpbook%2Fdjango-with-vuejs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tmpbook%2Fdjango-with-vuejs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tmpbook%2Fdjango-with-vuejs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tmpbook","download_url":"https://codeload.github.com/tmpbook/django-with-vuejs/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tmpbook%2Fdjango-with-vuejs/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30056070,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-03T18:21:05.932Z","status":"ssl_error","status_checked_at":"2026-03-03T18:20:59.341Z","response_time":61,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["devops","django","vuejs"],"created_at":"2026-03-03T19:34:00.587Z","updated_at":"2026-03-03T19:34:01.339Z","avatar_url":"https://github.com/tmpbook.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# django-with-vuejs\n\nFast \u0026 Clear in DevOps.\n\n[English README.md](/README-zh.md)\n\n\u003e 为什么 [Django Project](/examples/django-auth-with-react/backend) 目录和 [Frontend](/examples/django-auth-with-react/frontend) 目录均是在同级的 [example/django-auth-with-react](/examples/django-auth-with-react) 中，但是在 [project](/project) 目录中不是这样?\n\n这是因为 django-auth-with-react 项目是真正的前后端分离的，而 project 是 Django 去读取 index.html 的，并非真正的前后端分离。见 [#16](https://github.com/tmpbook/django-with-vuejs/issues/15)\n\n项目是最简版\n\n---\n\n### Step 1: 装前端依赖\n\n```\ncd django-with-vuejs/project/vue2_frontend\nnpm install\n```\n\n### Step 2: 构建前端\n\n在 vue2_frontend 目录构建前端页面\n\n```\nnpm run build\n```\n\n### Step 3: 通过 Django 自带 server 启动项目\n\nIn the directory where manage.py is located\n\n```\npip install -r requirements.txt\npython manage runserver\n```\n\n---\n\n## 更详细的教程\n\n这里: https://zhuanlan.zhihu.com/p/24893786\n\n## 与前端结合的原理\n\n前端构建完成就下面这两个资源\n\n- index.html\n- static/\\*\n\n让我们看看如何处理这两个资源\n\n### 第一个. index.html\n\n使用 [django template engines](https://docs.djangoproject.com/en/dev/topics/templates/) 去处理 `index.html` 文件\n\n在 `settings.py` 中\n\n```python\nTEMPLATES = [\n    {\n        'BACKEND': 'django.template.backends.django.DjangoTemplates',\n        # 'DIRS': [],\n        'DIRS': ['vue2_frontend/dist'],\n        'APP_DIRS': True,\n        'OPTIONS': {\n            'context_processors': [\n                'django.template.context_processors.debug',\n                'django.template.context_processors.request',\n                'django.contrib.auth.context_processors.auth',\n                'django.contrib.messages.context_processors.messages',\n            ],\n        },\n    },\n]\n```\n\n我们改变 `TEMPLATES.DIRS` 从而让 Django 能够找到 `index.html` 文件在哪。\n\n### 第二个. static/\\*\n\n同样是在 `settings.py` 中\n\n```python\nSTATIC_URL = '/static/'\n\nSTATICFILES_DIRS = [\n    os.path.join(BASE_DIR, \"vue2_frontend/dist/static\"),\n]\n```\n\n我们添加 `STATICFILES_DIRS` 配置，这个配置可以让 Django 找以下资源的时候：\n\n```html\n\u003cscript type=text/javascript src=/static/js/vendor.677ef0c9485c32b4f6a9.js\u003e\u003c/script\u003e\n```\n\n在 _vue2_frontend/dist/static_ 这个目录寻找，但是需要注意的是，这只在 django 的开发模式下才生效。\n\n## 生产环境\n\n我们在生产环境使用 Nginx 处理前端页面\n\n- index.html\n- static/\\*\n\n使用 Django 来开发 API，JSON 来传输数据。\n\n有任何问题 [New issues](https://github.com/tmpbook/django-with-vuejs/issues/new)\n\n### About me\n\n知乎：[临书](https://www.zhihu.com/people/tmpbook/activities)\n\n微信（WeChat）：\n\n\u003cdiv align=center\u003e\n    \u003cimg width=\"150\" height=\"150\" src=\"https://github.com/tmpbook/Django-with-ElasticSearch/blob/master/Wechat.jpeg\"/\u003e\n\u003c/div\u003e\n\n\u003cdiv align=right\u003e谢谢阅读\u003c/div\u003e\n\u003cdiv align=right\u003eThanks for watching\u003c/div\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftmpbook%2Fdjango-with-vuejs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftmpbook%2Fdjango-with-vuejs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftmpbook%2Fdjango-with-vuejs/lists"}