Giter Site home page Giter Site logo

gtalarico / django-vue-template Goto Github PK

View Code? Open in Web Editor NEW
1.6K 42.0 405.0 528 KB

Django Rest + Vue JS Template

Home Page: https://django-vue-template-demo.herokuapp.com/

License: MIT License

Python 50.17% HTML 3.61% Vue 27.45% JavaScript 18.78%
vuejs django django-rest-framework whitenoise rest-api vue vuecli

django-vue-template's Introduction

Django Vue Template ✌️ 🐍

Vue Logo Django Logo

This template is a minimal example for an application using Vue and Django.

Vue and Django are clearly separated in this project. Vue, Yarn and Webpack handles all frontend logic and bundling assessments. Django and Django REST framework to manage Data Models, Web API and serve static files.

While it's possible to add endpoints to serve django-rendered html responses, the intention is to use Django primarily for the backend, and have view rendering and routing and handled by Vue + Vue Router as a Single Page Application (SPA).

Out of the box, Django will serve the application entry point (index.html + bundled assets) at / , data at /api/, and static files at /static/. Django admin panel is also available at /admin/ and can be extended as needed.

The application templates from Vue CLI create and Django createproject are kept as close as possible to their original state, except where a different configuration is needed for better integration of the two frameworks.

Alternatives

If this setup is not what you are looking for, you might want look at other similar projects:

Prefer Flask? Checkout my gtalarico/flask-vuejs-template

Demo

Live Demo

Includes

  • Django
  • Django REST framework
  • Django Whitenoise, CDN Ready
  • Vue CLI 3
  • Vue Router
  • Vuex
  • Gunicorn
  • Configuration for Heroku Deployment

Template Structure

Location Content
/backend Django Project & Backend Config
/backend/api Django App (/api)
/src Vue App .
/src/main.js JS Application Entry Point
/public/index.html Html Application Entry Point (/)
/public/static Static Assets
/dist/ Bundled Assets Output (generated at yarn build)

Prerequisites

Before getting started you should have the following installed and running:

Setup Template

$ git clone https://github.com/gtalarico/django-vue-template
$ cd django-vue-template

Setup

$ yarn install
$ pipenv install --dev && pipenv shell
$ python manage.py migrate

Running Development Servers

$ python manage.py runserver

From another tab in the same directory:

$ yarn serve

The Vue application will be served from localhost:8080 and the Django API and static files will be served from localhost:8000.

The dual dev server setup allows you to take advantage of webpack's development server with hot module replacement. Proxy config in vue.config.js is used to route the requests back to django's API on port 8000.

If you would rather run a single dev server, you can run Django's development server only on :8000, and you have to build the Vue app first and the page will not reload on changes.

$ yarn build
$ python manage.py runserver

Pycharm additional configuration

Follow this guide to ensure you have pipenv setup

https://www.jetbrains.com/help/pycharm/pipenv.html

Click "Edit Configurations"

Select Django Server under templates

Click + to create a config from the templates

In Environment variables add

PYTHONUNBUFFERED=1;DJANGO_SETTINGS_MODULE=backend.settings.dev

Click Apply then Ok

Deploy

Heroku Server

$ heroku apps:create django-vue-template-demo
$ heroku git:remote --app django-vue-template-demo
$ heroku buildpacks:add --index 1 heroku/nodejs
$ heroku buildpacks:add --index 2 heroku/python
$ heroku addons:create heroku-postgresql:hobby-dev
$ heroku config:set DJANGO_SETTINGS_MODULE=backend.settings.prod
$ heroku config:set DJANGO_SECRET_KEY='...(your django SECRET_KEY value)...'

$ git push heroku

Heroku's nodejs buildpack will handle install for all the dependencies from the package.json file. It will then trigger the postinstall command which calls yarn build. This will create the bundled dist folder which will be served by whitenoise.

The python buildpack will detect the Pipfile and install all the python dependencies.

The Procfile will run Django migrations and then launch Django'S app using gunicorn, as recommended by heroku.

Heroku One Click Deploy

Deploy

Static Assets

See settings.dev and vue.config.js for notes on static assets strategy.

This template implements the approach suggested by Whitenoise Django. For more details see WhiteNoise Documentation

It uses Django Whitenoise to serve all static files and Vue bundled files at /static/. While it might seem inefficient, the issue is immediately solved by adding a CDN with Cloudfront or similar. Use vue.config.js > baseUrl option to set point all your assets to the CDN, and then set your CDN's origin back to your domains /static url.

Whitenoise will serve static files to your CDN once, but then those assets are cached and served directly by the CDN.

This allows for an extremely simple setup without the need for a separate static server.

Cloudfront Setup Wiki

django-vue-template's People

Contributors

bk202 avatar gtalarico avatar lclarkdwain avatar newbornfrontender avatar pawl avatar phlpeterdannemann avatar renzhengyu avatar shakib609 avatar soutys avatar wbeyda avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

django-vue-template's Issues

pipenv install --dev failed

realnot@venus:~/Workspace/django-vue-template$ pipenv install --dev Traceback (most recent call last): File "/home/realnot/.local/bin/pipenv", line 11, in <module> sys.exit(cli()) File "/home/realnot/.local/lib/python2.7/site-packages/pipenv/vendor/click/core.py", line 764, in __call__ return self.main(*args, **kwargs) File "/home/realnot/.local/lib/python2.7/site-packages/pipenv/vendor/click/core.py", line 717, in main rv = self.invoke(ctx) File "/home/realnot/.local/lib/python2.7/site-packages/pipenv/vendor/click/core.py", line 1137, in invoke return _process_result(sub_ctx.command.invoke(sub_ctx)) File "/home/realnot/.local/lib/python2.7/site-packages/pipenv/vendor/click/core.py", line 956, in invoke return ctx.invoke(self.callback, **ctx.params) File "/home/realnot/.local/lib/python2.7/site-packages/pipenv/vendor/click/core.py", line 555, in invoke return callback(*args, **kwargs) File "/home/realnot/.local/lib/python2.7/site-packages/pipenv/vendor/click/decorators.py", line 64, in new_func return ctx.invoke(f, obj, *args, **kwargs) File "/home/realnot/.local/lib/python2.7/site-packages/pipenv/vendor/click/core.py", line 555, in invoke return callback(*args, **kwargs) File "/home/realnot/.local/lib/python2.7/site-packages/pipenv/vendor/click/decorators.py", line 17, in new_func return f(get_current_context(), *args, **kwargs) File "/home/realnot/.local/lib/python2.7/site-packages/pipenv/cli/command.py", line 254, in install editable_packages=state.installstate.editables, File "/home/realnot/.local/lib/python2.7/site-packages/pipenv/core.py", line 1741, in do_install pypi_mirror=pypi_mirror, File "/home/realnot/.local/lib/python2.7/site-packages/pipenv/core.py", line 574, in ensure_project pypi_mirror=pypi_mirror, File "/home/realnot/.local/lib/python2.7/site-packages/pipenv/core.py", line 494, in ensure_virtualenv python = ensure_python(three=three, python=python) File "/home/realnot/.local/lib/python2.7/site-packages/pipenv/core.py", line 397, in ensure_python path_to_python = find_a_system_python(python) File "/home/realnot/.local/lib/python2.7/site-packages/pipenv/core.py", line 350, in find_a_system_python from .vendor.pythonfinder import Finder File "/home/realnot/.local/lib/python2.7/site-packages/pipenv/vendor/pythonfinder/__init__.py", line 14, in <module> from .pythonfinder import Finder File "/home/realnot/.local/lib/python2.7/site-packages/pipenv/vendor/pythonfinder/pythonfinder.py", line 6, in <module> from .models import SystemPath File "/home/realnot/.local/lib/python2.7/site-packages/pipenv/vendor/pythonfinder/models/__init__.py", line 11, in <module> from ..utils import KNOWN_EXTS, unnest File "/home/realnot/.local/lib/python2.7/site-packages/pipenv/vendor/pythonfinder/utils.py", line 27, in <module> from backports.functools_lru_cache import lru_cache ImportError: No module named functools_lru_cache

ImportError for django apps in INSTALLED_APPS on Heroku

No structural changes other than using the standard settings.py layout rather than separating dev & prod.

When running collectstatic Heroku is failing to build with an ImportError on my custom Django apps. This is not an issue locally.

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',

    'rest_framework',

    'users',
    'channels',
    'socials',
]

Down to rest_framework works fine, however, users, channels, socials are getting the ImportError.

-----> $ python manage.py collectstatic --noinput

       Traceback (most recent call last):

         File "manage.py", line 15, in <module>

           execute_from_command_line(sys.argv)

         File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line

           utility.execute()

         File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/__init__.py", line 357, in execute

           django.setup()

         File "/app/.heroku/python/lib/python3.6/site-packages/django/__init__.py", line 24, in setup

           apps.populate(settings.INSTALLED_APPS)

         File "/app/.heroku/python/lib/python3.6/site-packages/django/apps/registry.py", line 89, in populate

           app_config = AppConfig.create(entry)

         File "/app/.heroku/python/lib/python3.6/site-packages/django/apps/config.py", line 90, in create

           module = import_module(entry)

         File "/app/.heroku/python/lib/python3.6/importlib/__init__.py", line 126, in import_module

           return _bootstrap._gcd_import(name[level:], package, level)

         File "<frozen importlib._bootstrap>", line 994, in _gcd_import

         File "<frozen importlib._bootstrap>", line 971, in _find_and_load

         File "<frozen importlib._bootstrap>", line 953, in _find_and_load_unlocked

       ModuleNotFoundError: No module named 'users'

 !     Error while running '$ python manage.py collectstatic --noinput'.

       See traceback above for details.

       You may need to update application code to resolve this error.

       Or, you can disable collectstatic for this application:

          $ heroku config:set DISABLE_COLLECTSTATIC=1

       https://devcenter.heroku.com/articles/django-assets

 !     Push rejected, failed to compile Python app.

 !     Push failed

I do understand this is likely an issue on my end, however, I've deployed plenty of Django apps previously without this issue, but using this template prompts this issue so wondering if there's any immediate insight as to what may be happening?

File structure:
image

improvement suggestion: use named paths

I wondered in App.vue, what happens if we decide to change the path of a nav item?

<div id="nav">
      <router-link to="/">Vue</router-link> |
      <router-link to="/messages">Django Rest</router-link>
</div>

I think it would be better to use a named path, like this:

<div id="nav">
    <router-link :to="{ name: 'home' }">Vue</router-link> |
    <router-link :to="{ name: 'messages' }">Django Rest</router-link>
</div>

Initial settings: disableHostCheck, Cross-Origin

Hi, I appreciate your work!

When following the installation guide, it is not working out of the box. In
vue.config.js
I have to add

devServer: {
    disableHostCheck: true,
    ... 
}

to see the vue start page.

The web beowser console is repeatedly generating Cross-Origin blocks. So is some communication still bocked between vue and django by Cross-Origin rule of django or vue?
Am I doing something wrong or is it intended to be like this? Is djangos corsheaders needed to allow communication?

Using history mode for vue-router

Is there any way to configure django so the vue-router history mode will work. The hash mode in production doesn't look so great.

Love what you have made here and thank you!

Whitenoise 4.0 breaks Django 3.0

Hi, this project's Pipfile specifies Python 3.6, which I don't have installed locally, so I thought I'd bump it to 3.7 for my project. (Edit: this may or may not be actually related; maybe if someone has 3.6 installed they can check).

The Pipfile also specifies django = "*" (so Django 3.0 got installed) and whitenoise = "==4.0". However, whitenoise 4 is apparently not compatible with Django 3, because it tries to import from django.utils.six, which I guess has gone away in Django 3 (before, after). This resulted in errors like:

Exception in thread django-main-thread:
Traceback (most recent call last):
File "/home/ben/.local/share/virtualenvs/my-env-heqyJ-0V/lib/python3.7/site-packages/django/core/servers/basehttp.py", line 45, in get_internal_wsgi_application
return import_string(app_path)
File "/home/ben/.local/share/virtualenvs/my-env-heqyJ-0V/lib/python3.7/site-packages/django/utils/module_loading.py", line 17, in import_string
module = import_module(module_path)
File "/home/ben/.local/share/virtualenvs/my-env-heqyJ-0V/lib/python3.7/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 728, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/home/ben/local/my-env/backend/wsgi.py", line 18, in <module>
application = get_wsgi_application()
File "/home/ben/.local/share/virtualenvs/my-env-heqyJ-0V/lib/python3.7/site-packages/django/core/wsgi.py", line 13, in get_wsgi_application
return WSGIHandler()
File "/home/ben/.local/share/virtualenvs/my-env-heqyJ-0V/lib/python3.7/site-packages/django/core/handlers/wsgi.py", line 127, in __init__
self.load_middleware()
File "/home/ben/.local/share/virtualenvs/my-env-heqyJ-0V/lib/python3.7/site-packages/django/core/handlers/base.py", line 35, in load_middleware
middleware = import_string(middleware_path)
File "/home/ben/.local/share/virtualenvs/my-env-heqyJ-0V/lib/python3.7/site-packages/django/utils/module_loading.py", line 17, in import_string
module = import_module(module_path)
File "/home/ben/.local/share/virtualenvs/my-env-heqyJ-0V/lib/python3.7/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 728, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/home/ben/.local/share/virtualenvs/my-env-heqyJ-0V/lib/python3.7/site-packages/whitenoise/middleware.py", line 10, in <module>
from django.utils.six.moves.urllib.parse import urlparse
ModuleNotFoundError: No module named 'django.utils.six'

Whitenoise 5 is out, so this seemed to fix the problem for my purposes:

--- a/Pipfile
+++ b/Pipfile
@@ -7,11 +7,11 @@ name = "pypi"
 django = "*"
 djangorestframework = "*"
 gunicorn = "*"
-whitenoise = "==4.0"
+whitenoise = ">=5"
 dj-database-url = "*"
 psycopg2-binary = "*"
 
 [dev-packages]
 
 [requires]
-python_version = "3.6"
+python_version = "3.7"

Or alternatively you could specify Django 2.2 if you don't want to bump the Python and the Django versions.

Problems with server -- connection error or CORS --

HI @gtalarico !

I have a big problem with my game server, I am reading and trying since weeks but it does not want to be reachable from internet.

The server includes 3 applications:

Proxy (for the game connection)
Core (for listening ports and interact with the webserver)
Webserver (built with "npm run build")
I have tried to run it with "npm run serve" but i get issues with the CORS...
I have tried to to build it with "npm run build" and then I copied the built files from "\dist" to the Microsoft IIS server but i get "connection error".

I would really appreciate if someone could help me with the configuration because I am not a programmer and i have no idea about those languages.

PS: i can also send you the files privately too if you would like to help me

Error installing Vuetify

Hey,

Nice template - thanks for your effort creating this.

When I try and add Vuetify (via a 'vue add vuetify'), the plugin successfully installs, but I get around 95 errors when trying to serve. The errors are all

Syntax Error: SyntaxError: ..... Support for the experimental syntax 'objectRestSpread' isn't currently enabled

Add @babel/plugin-proposal-object-rest-spread (https://git.io/vb4Ss) to the 'plugins' section of your Babel config to enable transformation.

I'm fairly novice with JS and front-end frameworks - I've tried for sometime to fix this with no luck including trying to add the following to the package.json babel configuration.

"plugins": ["@babel/plugin-proposal-object-rest-spread"]

I guess I dont understand how the configuration of babel works in this template, or I am barking up the wrong tree.

Any help appreciated - thanks!

BW

Error

xxxx-Pro:django-vue-template zz$ python3 manage.py migrate
Traceback (most recent call last):
  File "manage.py", line 8, in <module>
    from django.core.management import execute_from_command_line
ModuleNotFoundError: No module named 'django'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "manage.py", line 14, in <module>
    ) from exc
ImportError: Couldn't import Django. Are you sure it's installed and available on your PYTHONPATH environment variable? Did you forget to activate a virtual environment?

I use Mac and something wrong.
Could u help me plz?

Application Error on Heroku

Was the app taken down from Heroku? I'm still using it as reference, especially now that I want to combine Nuxt + Django on Heroku..

运行manage.py报错

错误信息如下:
from django.utils.six.moves.urllib.parse import urlparse
ModuleNotFoundError: No module named 'django.utils.six'

将 whitenoise 版本升级为 5.2 后解决

Can we integrate another apps in django ?

Hello Im New in django, and i like somuch for your template ! ❤️

i just wanna ask something, if i make another apps in django-vue-template
with startapp and how to integrate with backend/api section?, bcuz when i create new apps in django they are in outside backend folder...

thanks.
best regards...

sorry for mybad english.

How do PostMessage and DeleteMessage work in the Message component?

Hi,

I know this may not be an "issue" per-se, but I can't figure out the following. In the Messages.vue file, we have the following code:

postMessage() {
      const payload = { subject: this.subject, body: this.msgBody };
      this.$backend.$postMessage(payload).then(() => {
        this.msgBody = ""
        this.subject = ""
        this.fetchMessages();
      });
    },
    deleteMsg(msgId) {
        this.$backend.$deleteMessage(msgId).then(() => {
            this.messages = this.messages.filter(m => m.pk !== msgId)
            this.fetchMessages();
        });
    }
  }

This to me looks a lot like "magic" because I don't see anywhere in our backend methods that correspond to "creating" or 'deleting" a message such as we see in the Django REST framework tutorial.

Whitenoise not working?

I have an app that's using this template and it doesn't seem like whitenoise is working. It's running on heroku and while the static files are being served correctly, they are not gzipped and don't have the a long Cache-Contol header on them. Any ideas?

Update:

I looks like the admin static files are being correctly cached and compressed, just not the js/css from the Vue app. Does anyone know how I can enable compression and caching for these files as well?

TemplateDoesNotExist at

After completing the installation I'm running the following command
python manage.py runserver
All the urls paths are working except
path('', index_view, name='index')
This results in a TemplateDoesNotExist error. What am I doing wrong here?

Authentication and Permissions

I am still learning DRF and Vue, so can you add how a basic authentication and permissions can work? I am able to post and delete via the rest api, but unable to do via Vue. To give a test case, I want to AllowAny to post, but users needs to be authenticated to edit/delete.

ImproperlyConfigured: Cannot import 'api'.

Just follow your readme, and it's throw an error

django.core.exceptions.ImproperlyConfigured: Cannot import 'api'. Check that 'backend.api.apps.AppConfig.name' is correct.

while i ran
python manage.py migrate

http://localhost:8080/sockjs-node errors

First off, thanks for the great template. The browser console reports errors trying to connect to http://localhost:8080/sockjs-node/..., because the dev server isn't listening on localhost but instead the host IP. How do you change the development server to listen on localhost as well? I tried setting "host:'localhost'" in vue.config.js but it is ignored. Alternately, how do you point those sockjs-node calls to the hostname rather than localhost?

Error: yarn build

$ yarn build






|  Building for production...

 ERROR  Failed to compile with 3 errors                                 11:32:56

 error  in ./src/App.vue?vue&type=style&index=0&lang=css&

Module build failed (from ./node_modules/mini-css-extract-plugin/dist/loader.js)
:
TypeError: this[NS] is not a function
    at D:\Documents\Coding\web\django-vue-template\node_modules\mini-css-extract
-plugin\dist\loader.js:148:15
    at D:\Documents\Coding\Web\django-vue-template\node_modules\webpack\lib\Comp
iler.js:296:11
    at D:\Documents\Coding\Web\django-vue-template\node_modules\webpack\lib\Comp
iler.js:553:14
    at AsyncSeriesHook.eval [as callAsync] (eval at create (D:\Documents\Coding\
Web\django-vue-template\node_modules\tapable\lib\HookCodeFactory.js:24:12), <ano
nymous>:13:1)
    at AsyncSeriesHook.lazyCompileHook [as _callAsync] (D:\Documents\Coding\Web\
django-vue-template\node_modules\tapable\lib\Hook.js:35:21)
    at D:\Documents\Coding\Web\django-vue-template\node_modules\webpack\lib\Comp
iler.js:550:30
    at AsyncSeriesHook.eval [as callAsync] (eval at create (D:\Documents\Coding\
Web\django-vue-template\node_modules\tapable\lib\HookCodeFactory.js:24:12), <ano
nymous>:4:1)
    at AsyncSeriesHook.lazyCompileHook [as _callAsync] (D:\Documents\Coding\Web\
django-vue-template\node_modules\tapable\lib\Hook.js:35:21)
    at D:\Documents\Coding\Web\django-vue-template\node_modules\webpack\lib\Comp
ilation.js:1294:35
    at AsyncSeriesHook.eval [as callAsync] (eval at create (D:\Documents\Coding\
Web\django-vue-template\node_modules\tapable\lib\HookCodeFactory.js:24:12), <ano
nymous>:4:1)
    at AsyncSeriesHook.lazyCompileHook [as _callAsync] (D:\Documents\Coding\Web\
django-vue-template\node_modules\tapable\lib\Hook.js:35:21)
    at D:\Documents\Coding\Web\django-vue-template\node_modules\webpack\lib\Comp
ilation.js:1285:32
    at eval (eval at create (D:\Documents\Coding\Web\django-vue-template\node_mo
dules\tapable\lib\HookCodeFactory.js:24:12), <anonymous>:9:1)
    at D:\Documents\Coding\Web\django-vue-template\node_modules\uglifyjs-webpack
-plugin\dist\index.js:282:11
    at _class.runTasks (D:\Documents\Coding\Web\django-vue-template\node_modules
\uglifyjs-webpack-plugin\dist\uglify\index.js:63:9)
    at UglifyJsPlugin.optimizeFn (D:\Documents\Coding\Web\django-vue-template\no
de_modules\uglifyjs-webpack-plugin\dist\index.js:195:16)
    at AsyncSeriesHook.eval [as callAsync] (eval at create (D:\Documents\Coding\
Web\django-vue-template\node_modules\tapable\lib\HookCodeFactory.js:24:12), <ano
nymous>:5:1)
    at AsyncSeriesHook.lazyCompileHook [as _callAsync] (D:\Documents\Coding\Web\
django-vue-template\node_modules\tapable\lib\Hook.js:35:21)
    at D:\Documents\Coding\Web\django-vue-template\node_modules\webpack\lib\Comp
ilation.js:1280:36
    at AsyncSeriesHook.eval [as callAsync] (eval at create (D:\Documents\Coding\
Web\django-vue-template\node_modules\tapable\lib\HookCodeFactory.js:24:12), <ano
nymous>:4:1)
    at AsyncSeriesHook.lazyCompileHook [as _callAsync] (D:\Documents\Coding\Web\
django-vue-template\node_modules\tapable\lib\Hook.js:35:21)
    at D:\Documents\Coding\Web\django-vue-template\node_modules\webpack\lib\Comp
ilation.js:1276:32

 @ ./src/App.vue?vue&type=style&index=0&lang=css& 1:0-403 1:419-422 1:424-824 1:
424-824
 @ ./src/App.vue
 @ ./src/main.js
 @ multi ./src/main.js

 error  in ./src/components/VueDemo.vue?vue&type=style&index=0&id=1fef0148&scope
d=true&lang=css&

Module build failed (from ./node_modules/mini-css-extract-plugin/dist/loader.js)
:
TypeError: this[NS] is not a function
    at D:\Documents\Coding\web\django-vue-template\node_modules\mini-css-extract
-plugin\dist\loader.js:148:15
    at D:\Documents\Coding\Web\django-vue-template\node_modules\webpack\lib\Comp
iler.js:296:11
    at D:\Documents\Coding\Web\django-vue-template\node_modules\webpack\lib\Comp
iler.js:553:14
    at AsyncSeriesHook.eval [as callAsync] (eval at create (D:\Documents\Coding\
Web\django-vue-template\node_modules\tapable\lib\HookCodeFactory.js:24:12), <ano
nymous>:13:1)
    at AsyncSeriesHook.lazyCompileHook [as _callAsync] (D:\Documents\Coding\Web\
django-vue-template\node_modules\tapable\lib\Hook.js:35:21)
    at D:\Documents\Coding\Web\django-vue-template\node_modules\webpack\lib\Comp
iler.js:550:30
    at AsyncSeriesHook.eval [as callAsync] (eval at create (D:\Documents\Coding\
Web\django-vue-template\node_modules\tapable\lib\HookCodeFactory.js:24:12), <ano
nymous>:4:1)
    at AsyncSeriesHook.lazyCompileHook [as _callAsync] (D:\Documents\Coding\Web\
django-vue-template\node_modules\tapable\lib\Hook.js:35:21)
    at D:\Documents\Coding\Web\django-vue-template\node_modules\webpack\lib\Comp
ilation.js:1294:35
    at AsyncSeriesHook.eval [as callAsync] (eval at create (D:\Documents\Coding\
Web\django-vue-template\node_modules\tapable\lib\HookCodeFactory.js:24:12), <ano
nymous>:4:1)
    at AsyncSeriesHook.lazyCompileHook [as _callAsync] (D:\Documents\Coding\Web\
django-vue-template\node_modules\tapable\lib\Hook.js:35:21)
    at D:\Documents\Coding\Web\django-vue-template\node_modules\webpack\lib\Comp
ilation.js:1285:32
    at eval (eval at create (D:\Documents\Coding\Web\django-vue-template\node_mo
dules\tapable\lib\HookCodeFactory.js:24:12), <anonymous>:9:1)
    at D:\Documents\Coding\Web\django-vue-template\node_modules\uglifyjs-webpack
-plugin\dist\index.js:282:11
    at _class.runTasks (D:\Documents\Coding\Web\django-vue-template\node_modules
\uglifyjs-webpack-plugin\dist\uglify\index.js:63:9)
    at UglifyJsPlugin.optimizeFn (D:\Documents\Coding\Web\django-vue-template\no
de_modules\uglifyjs-webpack-plugin\dist\index.js:195:16)
    at AsyncSeriesHook.eval [as callAsync] (eval at create (D:\Documents\Coding\
Web\django-vue-template\node_modules\tapable\lib\HookCodeFactory.js:24:12), <ano
nymous>:5:1)
    at AsyncSeriesHook.lazyCompileHook [as _callAsync] (D:\Documents\Coding\Web\
django-vue-template\node_modules\tapable\lib\Hook.js:35:21)
    at D:\Documents\Coding\Web\django-vue-template\node_modules\webpack\lib\Comp
ilation.js:1280:36
    at AsyncSeriesHook.eval [as callAsync] (eval at create (D:\Documents\Coding\
Web\django-vue-template\node_modules\tapable\lib\HookCodeFactory.js:24:12), <ano
nymous>:4:1)
    at AsyncSeriesHook.lazyCompileHook [as _callAsync] (D:\Documents\Coding\Web\
django-vue-template\node_modules\tapable\lib\Hook.js:35:21)
    at D:\Documents\Coding\Web\django-vue-template\node_modules\webpack\lib\Comp
ilation.js:1276:32

 @ ./src/components/VueDemo.vue?vue&type=style&index=0&id=1fef0148&scoped=true&l
ang=css& 1:0-449 1:465-468 1:470-916 1:470-916
 @ ./src/components/VueDemo.vue
 @ ./src/router.js
 @ ./src/main.js
 @ multi ./src/main.js

 error  in ./src/components/Messages.vue?vue&type=style&index=0&id=34ae3f99&scop
ed=true&lang=css&

Module build failed (from ./node_modules/mini-css-extract-plugin/dist/loader.js)
:
TypeError: this[NS] is not a function
    at D:\Documents\Coding\web\django-vue-template\node_modules\mini-css-extract
-plugin\dist\loader.js:148:15
    at D:\Documents\Coding\Web\django-vue-template\node_modules\webpack\lib\Comp
iler.js:296:11
    at D:\Documents\Coding\Web\django-vue-template\node_modules\webpack\lib\Comp
iler.js:553:14
    at AsyncSeriesHook.eval [as callAsync] (eval at create (D:\Documents\Coding\
Web\django-vue-template\node_modules\tapable\lib\HookCodeFactory.js:24:12), <ano
nymous>:13:1)
    at AsyncSeriesHook.lazyCompileHook [as _callAsync] (D:\Documents\Coding\Web\
django-vue-template\node_modules\tapable\lib\Hook.js:35:21)
    at D:\Documents\Coding\Web\django-vue-template\node_modules\webpack\lib\Comp
iler.js:550:30
    at AsyncSeriesHook.eval [as callAsync] (eval at create (D:\Documents\Coding\
Web\django-vue-template\node_modules\tapable\lib\HookCodeFactory.js:24:12), <ano
nymous>:4:1)
    at AsyncSeriesHook.lazyCompileHook [as _callAsync] (D:\Documents\Coding\Web\
django-vue-template\node_modules\tapable\lib\Hook.js:35:21)
    at D:\Documents\Coding\Web\django-vue-template\node_modules\webpack\lib\Comp
ilation.js:1294:35
    at AsyncSeriesHook.eval [as callAsync] (eval at create (D:\Documents\Coding\
Web\django-vue-template\node_modules\tapable\lib\HookCodeFactory.js:24:12), <ano
nymous>:4:1)
    at AsyncSeriesHook.lazyCompileHook [as _callAsync] (D:\Documents\Coding\Web\
django-vue-template\node_modules\tapable\lib\Hook.js:35:21)
    at D:\Documents\Coding\Web\django-vue-template\node_modules\webpack\lib\Comp
ilation.js:1285:32
    at eval (eval at create (D:\Documents\Coding\Web\django-vue-template\node_mo
dules\tapable\lib\HookCodeFactory.js:24:12), <anonymous>:9:1)
    at D:\Documents\Coding\Web\django-vue-template\node_modules\uglifyjs-webpack
-plugin\dist\index.js:282:11
    at _class.runTasks (D:\Documents\Coding\Web\django-vue-template\node_modules
\uglifyjs-webpack-plugin\dist\uglify\index.js:63:9)
    at UglifyJsPlugin.optimizeFn (D:\Documents\Coding\Web\django-vue-template\no
de_modules\uglifyjs-webpack-plugin\dist\index.js:195:16)
    at AsyncSeriesHook.eval [as callAsync] (eval at create (D:\Documents\Coding\
Web\django-vue-template\node_modules\tapable\lib\HookCodeFactory.js:24:12), <ano
nymous>:5:1)
    at AsyncSeriesHook.lazyCompileHook [as _callAsync] (D:\Documents\Coding\Web\
django-vue-template\node_modules\tapable\lib\Hook.js:35:21)
    at D:\Documents\Coding\Web\django-vue-template\node_modules\webpack\lib\Comp
ilation.js:1280:36
    at AsyncSeriesHook.eval [as callAsync] (eval at create (D:\Documents\Coding\
Web\django-vue-template\node_modules\tapable\lib\HookCodeFactory.js:24:12), <ano
nymous>:4:1)
    at AsyncSeriesHook.lazyCompileHook [as _callAsync] (D:\Documents\Coding\Web\
django-vue-template\node_modules\tapable\lib\Hook.js:35:21)
    at D:\Documents\Coding\Web\django-vue-template\node_modules\webpack\lib\Comp
ilation.js:1276:32

 @ ./src/components/Messages.vue?vue&type=style&index=0&id=34ae3f99&scoped=true&
lang=css& 1:0-450 1:466-469 1:471-918 1:471-918
 @ ./src/components/Messages.vue
 @ ./src/router.js
 @ ./src/main.js
 @ multi ./src/main.js

 ERROR  Build failed with errors.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Question about TEMPLATES config

I have a question about the TEMPLATES config in this project. It looks like this"

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        # Add dist to
        'DIRS': ['dist'],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]

As we see 'DIRS' has a list that looks like this ['dist']. I want to know how the Django finds this directory which is outside of the Django project directory?

yarn serve doesn't refresh django app

Hi! I like this template a lot.

One question / issue.

I start two servers, as recommended in the README

python manage.py runserver
yarn serve  # in another tab

When I edit the JavaScript, it looks like the files are re-compiled, but I don't see any changes in the Django app. It seems like the Django app is just serving the js in the dist/ directory, and the whatever files vue is re-compiling are held in memory, not written to that dist/ directory.

It seems like the intention with the project is that if both servers are running at the same time you can edit the JS and Django will serve the re-loaded files. Is that correct? Am I missing something, or is this an error in this code?

I get 404 page after on page reload

I deployed an app on Heroku. The app was created using this template.
I have a problem with the app, the problem is: when I navigate to a route like this /catg-1 and after I refresh I get a 404 page.
Note that I use history mode in vue-router.
These are the URL in my Django project:

backend/urls.py

urlpatterns = [

    # http://localhost:8000/
    path('', index_view, name='index'),

    # http://localhost:8000/api/admin/
    path('admin/', admin.site.urls),

    path('api/bookmarks/', include('backend.bookmarks.urls')),

]

backend/bookmars/urls.py

urlpatterns = [
    path('category/', CategoryListAPIView.as_view()),
    path('category/<slug:slug>/', CategoryAPIDetail.as_view(),),
    path('category/<slug:slug>/bookmarks/', BookmarkByCategoryAPIList.as_view()),
    path('bookmark/', BookmarkAPICreate.as_view()),
    path('bookmark/<slug:slug>/', BookmarkAPIDetail.as_view()),
    path('get-page-title/<path:url>', get_page_title_view),
    path('check-url-existence/<path:url>', check_url_existing_view,),
]

And this is the vue.config.js file:

const IS_PRODUCTION = process.env.NODE_ENV === 'production'

module.exports = {
    outputDir: 'dist',
    assetsDir: 'static',
    publicPath: IS_PRODUCTION
    ? 'http://vue-django-bookmark.herokuapp.com/'
    : '/',
    // For Production, replace set baseUrl to CDN
    // And set the CDN origin to `yourdomain.com/static`
    // Whitenoise will serve once to CDN which will then cache
    // and distribute
    devServer: {
      proxy: {
        '/api*': {
          // Forward frontend dev server request for /api to django dev server
          target: 'http://localhost:8888/',
        }
      }
    }
  }

routes from router.js:

export default new Router({
  routes: [
    {
      path: "/",
      component: Home,
      name: 'Home',
    },
    {
      path: "/:category",
      component: Bookmarks,
      name: "Bookmarks",
    },
  ],
  mode: "history",
})

Any help, please?

Thank you in advance.

Error: White Noise

I have yet to understand what DjangoWhiteNoise does, but when I use the command py manage.py runserver without making any changes I get the following error.

C:\KBaseDjango>py manage.py runserver
Performing system checks...

System check identified no issues (0 silenced).
August 14, 2018 - 10:28:54
Django version 2.0.6, using settings 'backend.settings.dev'
Starting development server at http://127.0.0.1:8000/
Quit the server with CTRL-BREAK.
Unhandled exception in thread started by <function check_errors.<locals>.wrapper
 at 0x0000000004FDAC80>
Traceback (most recent call last):
  File "C:\Installs\Python\lib\site-packages\django\core\servers\basehttp.py", l
ine 44, in get_internal_wsgi_application
    return import_string(app_path)
  File "C:\Installs\Python\lib\site-packages\django\utils\module_loading.py", li
ne 17, in import_string
    module = import_module(module_path)
  File "C:\Installs\Python\lib\importlib\__init__.py", line 126, in import_modul
e
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 978, in _gcd_import
  File "<frozen importlib._bootstrap>", line 961, in _find_and_load
  File "<frozen importlib._bootstrap>", line 950, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 655, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 678, in exec_module
  File "<frozen importlib._bootstrap>", line 205, in _call_with_frames_removed
  File "C:\KBaseDjango\backend\wsgi.py", line 13, in <module>
    from whitenoise.django import DjangoWhiteNoise
  File "C:\Installs\Python\lib\site-packages\whitenoise\django.py", line 2, in <
module>
    '\n\n'
ImportError:

Your WhiteNoise configuration is incompatible with WhiteNoise v4.0
This can be fixed by following the upgrade instructions at:
http://whitenoise.evans.io/en/stable/changelog.html#v4-0



The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "C:\Installs\Python\lib\site-packages\django\utils\autoreload.py", line 2
25, in wrapper
    fn(*args, **kwargs)
  File "C:\Installs\Python\lib\site-packages\django\core\management\commands\run
server.py", line 140, in inner_run
    handler = self.get_handler(*args, **options)
  File "C:\Installs\Python\lib\site-packages\django\contrib\staticfiles\manageme
nt\commands\runserver.py", line 27, in get_handler
    handler = super().get_handler(*args, **options)
  File "C:\Installs\Python\lib\site-packages\django\core\management\commands\run
server.py", line 65, in get_handler
    return get_internal_wsgi_application()
  File "C:\Installs\Python\lib\site-packages\django\core\servers\basehttp.py", l
ine 49, in get_internal_wsgi_application
    ) from err
django.core.exceptions.ImproperlyConfigured: WSGI application 'backend.wsgi.appl
ication' could not be loaded; Error importing module.

I edited the backend/settings/wsgi.py file and commented out lines to remove references to White Noise as per the instructions in the WhiteNoise documentation and everything seems to be running fine.

I am using Django 2.0.6

psycopg2 deprecated

Latest psycopg2 recommends using the pip installation name "psycopg2-binary" instead of the previous "psycopg2" in pipfile/requirements.txt

GitHub discussion

Could you consider to open github discussion for new features/proposals and everything related? I have many questions and so maybe others too. Thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.