Coder Social home page Coder Social logo

metakermit / django-spa Goto Github PK

View Code? Open in Web Editor NEW
96.0 96.0 19.0 167 KB

Simple Django configuration to serve a single-page app

License: MIT License

Makefile 12.13% Python 86.94% HTML 0.93%
angular django django-rest-framework heroku react spa whitenoise

django-spa's People

Contributors

dependabot[bot] avatar metakermit avatar pyup-bot avatar vbobcat 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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

django-spa's Issues

Django-React - No CSRF Cookie Set

  • django-spa version:
  • Python version:
  • Operating System:

Description

I have the requirement to get a CSRF cookie set but can't find a way to inject the token.

What I Did

Just use CRA with a script to copy the build folder into the static folder for the Django site after build.

How to set custom name for static files directory?

  • django-spa version: 0.2.0
  • Python version: 3.7
  • Operating System: various

Description

My hosting forces me to keep static files in public/static/ directory, which does not seem to work with this library. Is there a way to change it?

Serving CRA static assets since django-spa 3.x

Hi @metakermit,

We're using django-spa in a few of our production applications. When support was added for Django 3, a change was introduced that broke the way we your module.

By default, Create React App places JavaScript and CSS files inside the build/static directory. There isn't a clear way to change this. We place the contents of the build/ directory into Django's static root.

Before the change, django-spa could search under static/static/.... With the new logic, the module won't append /static/ to the OS search path, which means the React assets are inaccessible.

For more context, this is what our directory structure looks like:

$ ls -dl django/static/*
drwxr-xr-x 6 root root 4096 Jul 30 13:50 django/static/admin
-rw-r--r-- 1 root root 1099 Jul 30 13:50 django/static/asset-manifest.json
-rw-r--r-- 1 root root 3150 Jul 30 13:50 django/static/favicon.ico
-rw-r--r-- 1 root root 2270 Jul 30 13:50 django/static/index.html
-rw-r--r-- 1 root root 5347 Jul 30 13:50 django/static/logo192.png
-rw-r--r-- 1 root root 9664 Jul 30 13:50 django/static/logo512.png
-rw-r--r-- 1 root root  492 Jul 30 13:50 django/static/manifest.json
-rw-r--r-- 1 root root  763 Jul 30 13:50 django/static/precache-manifest.833ab0b0246e3d77e7b8cc6bf371435d.js
-rw-r--r-- 1 root root   67 Jul 30 13:50 django/static/robots.txt
-rw-r--r-- 1 root root 1181 Jul 30 13:50 django/static/service-worker.js
drwxr-xr-x 5 root root 4096 Jul 30 13:50 django/static/static
-rw-r--r-- 1 root root 9608 Jul 30 13:50 django/static/staticfiles.json
$ ls -dl django/static/static/*
drwxr-xr-x 2 root root 4096 Jul 30 13:50 django/static/static/css
drwxr-xr-x 2 root root 4096 Jul 30 13:50 django/static/static/js
drwxr-xr-x 2 root root 4096 Jul 30 13:50 django/static/static/media

I can see why the logic was tweaked in the module. You could make the case that it working before was a bug.

I tried to work around the problem by configuring the static root and static url to be /assets/. This works, however index.html is no longer served on /. Presumably, this is because index_name is not configurable.

How would you recommend we upgrade to the 0.3.x series of your module? Do you know any examples of others using django-spa to serve React frontends?

I'd appreciate any insight 🙏 .

Django 3.0

  • django-spa version: 0.2.0
  • Python version: 3.8.0
  • Operating System: Windows

This package requires using whitenoise 3.2.2, which doesn't work with django 3.0.
Is this repository still maintained?

manage.py collectstatic not working when file path starts with /static/

A static file is not found when using Whitenoise compression (STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'):

$ python manage.py collectstatic --noinput
whitenoise.storage.MissingFileError: The file 'media/pb-logo.6a30f15f.svg' could not be found with <whitenoise.storage.CompressedManifestStaticFilesStorage object at 0x7f005c68f400>.
The CSS file 'static/css/main.0b53b962.css' references a file which could not be found:
  media/pb-logo.6a30f15f.svg
Please check the URL references in this CSS file, particularly any
relative paths which might be pointing to the wrong location.

Even though it should be there – this is the CSS:

.pb-logo {
  background-image: url(/static/media/pb-logo.6a30f15f.svg);
}

and the file layout is:

posterbat/static
├── 404.html
├── asset-manifest.json
├── favicon.ico
├── index.html
├── manifest.json
├── robots.txt
├── service-worker.js
└── static
    ├── css
    │   ├── main.0b53b962.css
    │   └── main.0b53b962.css.map
    ├── js
    │   ├── main.88d68361.js
    │   └── main.88d68361.js.map
    └── media
        └── pb-logo.6a30f15f.svg

Loading Django Admin's assets partially

  • django-spa version: 0.3.5
  • Django version: 2.1.7
  • Python version: 3.7.6
  • Operating System: macOS / Ubuntu 18.04 (Heroku-18)

Description

Describe what you were trying to get done.
Tell us what happened, what went wrong, and what you expected to happen.

I have a Django application in which I'd like to serve my SPA, bootstrapped with Create React App. In production the application is served by daphne. (version 2.2.5)

I followed the guide provided and the SPA is served well but in Django Admin I noticed that the assets are not loading properly. Most noticeably, missing icons and fonts.

I did not experience any missing resources. All resources were properly loaded.

What I Did

  • Looked into what is served and I noticed that /static/admin/css/base.[hash].css was missing the icons
  • Did the installation process step-by-step and checked when this weird behaviour starts
  • Figured out that it has to do something with the STATICFILES_STORAGE because when I change it from 'spa.storage.SPAStaticFilesStorage' to'whitenoise.storage.CompressedManifestStaticFilesStorage' the admin assets were loaded
python manage.py collectstatic --clear --noinput
daphne -b 0.0.0.0 -p 1234 boshi.asgi:application

Let me know if I can help.

Support for non '/' SPA Root

Hi,

Thanks for the awesome work!

Is there any plan to support non "/" or "/index.html" spa roots?

In my use case, my spa root is at "/dashboard", while my "/" is a plain old regular django template.

Cheers,

Conflicting dependencies error message (whitenoise 5.2.0 vs. django-spa 0.3.5)

This is about django-spa 0.3.5. I'm running Python 3.8.5 on Windows 10 64bits.

When running pip install -r requirements.txt --use-feature 2020-resolver for my project dependencies, I receive this message:

ERROR: Cannot install whitenoise==5.2.0 and django-spa 0.3.5 because these package versions have conflicting dependencies.

The conflict is caused by:
    The user requested whitenoise==5.2.0
    django-spa 0.3.5 depends on whitenoise==5.0.1

To fix this you could try to:
1. loosen the range of package versions you've specified
2. remove package versions to allow pip attempt to solve the dependency conflict

ERROR: ResolutionImpossible: for help visit https://pip.pypa.io/en/latest/user_guide/#fixing-conflicting-dependencies

Is there any actual breaking incompatibility caused by whitenoise versions later than 5.0.1, which is the one required by django-spa 0.35?

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.