I'm a new developer on Django and I want to use some CoffeeScript in my dummy project. However, documentation about this topic isn't good and I want to know from the experts which is the best option.
I was looking at possibilities like compressor but it is still confused. I'd really appreciate some pieces of advice.
Thanks in advance.
For automatic compilation, there's django-coffeescript. For a more complete toolchain (a bit like Rails Sprockets) there's Gears, a stand-alone project with plugins for Django, Flask or compilation on the command line.
When I've used CoffeeScript with Django however, I've mostly preferred to set up compilation as a part of a build process (great to have one in any case), there I mostly used custom Paver scripts together with directory watching tools (like watchdog/kicker) to compile .coffee files to Javascript and putting them in my static directory.
What exactly is your question? Django will let you use any JS libary you want. Just add it your HTML pages or templates as you would do without Django.
If it is about serving of staticfiles, check this: https://docs.djangoproject.com/en/1.4/ref/contrib/staticfiles/
Related
Im looking for a reasonably simple toolset and workflow for incorporating Sass into my Django projects. Im predominantly backend focused and have just started investigating Sass, so bear with me.
My initial idea was to keep things simple by just using node-sass without trying to incorporate Gulp, django-pipeline or anything else initially.
My Django apps are usually structured such that I create a static/app/css folder in each app. One option I guess would be to now create an additional folder per app for scss files, ie: static/app/scss. The problem there would be that when running collectstatic in production, the scss files will be gathered as well. So should the scss files for each app be kept somewhere else? (I guess it doesn't really matter if the scss files are included when collectstatic runs?)
Next, outside of my Django project folders I would create a folder to install node-sass since I wouldn't want to install it globally and I don't want the node-modules folder inside my Django project or inside source control.
I guess the node-modules folder can be thought of like using a python virtualenv instead of installing packages globally?
Next, inside my Django project somewhere (not sure where?) I would have the package.json file containing a scripts section for every scss file I want compiled to css, eg:
"scripts": {
"compile:sass": "node-sass app1/static/app1/scss/style.scss app1/static/app1/css/style.css",
"compile:sass": "node-sass app2/static/app2/scss/style.scss app2/static/app2/css/style.css",
"compile:sass": "node-sass app3/static/app3/scss/style.scss app3/static/app3/css/style.css"
}
Lastly, I would just run compile:sass with the watch flag to constantly compile any files I work on and put them in the correct folders.
So my questions are, is the above setup a good approach (at least initially if im not ready to add yet another tool like Gulp etc to the mix)?
Also, how will I run compile:sass considering my package.json file will be in the Django project somewhere and the node-modules folder containing the node-sass installation will be somewhere else.
I help maintain node-sass, so I won't say not to use it. There is an alternate libsass-python that you might want to look at if you're working with Python though.
Check out the django-sass-processor package. It's simple to configure and use. I've used it a few times and have had good experiences with it. The package abstracts away Gulp, so you don't have to worry about it and streamlines the whole process.
Here's a tutorial on how to integrate django-sass-processor into a Django project.
I am setting up the asset pipeline for a new project. We already use React.js along with webpack in a gulp-based build system and would like to use React for the new project as well. Now, since the application is written in django, I would like to port the pipeline to django-pipeline.
Ok, I can replace webpack with pipeline-browserify, and there's also PyReact for jsx compiling. But I am unable to pipe my jsx files first through the JSX compiler and then to browserify. As far as I can tell, there is just a single compiler stage with django-pipeline. Or am I missing something? Please tell me I'm wrong...
Thanks!
My quick way for dealing with this was just to also use the reactify plugin for browserify and adding PIPELINE_BROWSERIFY_ARGUMENTS = '-t reactify' to my Django settings.
Django-pipeline does support putting multiple compilers, though in my particular case, since I've used browserify more than django-pipeline, I used the single browserify compiler instead.
I'm trying to integrate the Famous libraries into an existing web application and the usage of requireJS with separate Famous JS files is giving me headaches. The existing web application does not use requireJS and it would be a big project to retrofit it to do so.
However, when I look at this demo:
http://demo.famo.us/tentacles/
A "famous.lib.js" file is included which encapsulates all the requireJS functionality into a single file.
How is this file generated? Does the Famous toolchain allow for creating this? If so, what is the command used?
The generator-famous docs say: "A single command to prepare your project for production". That may be what I'm looking for, but I'm not sure of the syntax for that command.
Does anyone know?
Yes. The single command is simply 'grunt'
Run 'grunt' in your application's directory and it will create a distribution folder called 'dist'
Inside 'dist' you will find everything compact and ready to go.
I'd like to starting use Foundation 5 in a django project.
My doubts are about how to setup folders of Foundation project.
Foundation now uses bower for js dipendencies.
I think it's not correct make a foundation 5 set up into the static folder of django.
Has anyone done a setup of foundation in a django project?
To compile scss files I'll use django-compressor.
My solution is use django-bower... that's all!
Check here. It should have all the instructions.
https://pypi.python.org/pypi/django-zurb-foundation
I've been playing with foundation on my django project using the django development server. All I did was download the Foundation 5 static files (JS,CSS) and add them to my django static files. Then I added in the necessary scripts to my base template as shown here: http://foundation.zurb.com/docs/css.html. I haven't put it into production yet but I don't see any reason why that wouldn't work or why using static files isn't correct (as you thought in your question).
There are benefits to compiling the CSS yourself with SASS if you're really hardcore and I imagine that using template tags with django-zurb-foundation is a little cleaner or maybe easier to implement if you have tons of templates that you would need to modify but if you're like me and you just want to try Foundation out on a small project then downloading the extra applications (django-bower, django-zurb-foundation) isn't necessary.
I am using Sphinx to generate documentation for a Django project, and it is working really well. However it seems to be necessary to write the .rst files yourself, and once that is done, sphinx will compile the documentation from the docstrings when you run make HTML.
My questions is:
I am looking for the docs to reflect new additions to the project automatically without having to edit the .rst files manually.
As everything in Django always seems so simple, I find it odd that you have to create the rst files for the entire project manually, I would have thought that there is something that already exists, that automatically inspects the structure of the project, and builds the rst's from that.
I have looked at this project http://pypi.python.org/pypi/django-sphinx-autodoc/0.0 which looks promising, but I am surprised that there is not something more mature.
Since a while, Sphinx apidoc is bundled with Sphinx. This can create a full set of .rst files for you.
It becomes more of a problem if you want to document all the various django applications that you use in one site (this seems to be what you want). Sphinx apidoc wants a bunch of directories to scan for python packages.