why my django groundwork doesn't work - django

I install django-groundwork by pip and set add 'groundwork' to the my django app but it seems doesn't work,I don't know why?When I use command 'python manage.py help' to check which command could be used ,there is no 'ground' but the module dose exist.Please give me some help

The groundwork pagkage doesn't provide any management commands. It only provides some templates and template tags. That's why you're not seeing anything when calling manage.py (or django-admin.py'
The docs say it clearly, but you can check out the code... there's simply no management/commands directory inside the installed package.
Groundwork is a small set of template tags and filters that simplifies
working with Zurb Foundation
To truly say that the application "doesn't work", you'd have to use the template tags it provides.
Do this in a template
{% load groundwork_tags %}
Then do this
{% groundwork_icon 'info' '5em' 'text-centered' %}
If that breaks your template, it means the app isn't properly installed, is broken, or otherwise there's something else wrong.
Read about django management commands a little, it will all be clear (make sure to read about the version of django that you have installed.. the link will always point to the development version so things might be different there):
https://docs.djangoproject.com/en/dev/howto/custom-management-commands/

Related

Custon DjangoTemplates for one app

I want to use a third party app that did not use adequate django principles:
templates \w hard coded urls instead of {% url ... %} syntax
templates \w hard coded static files instead of {% static ... %} syntax
makemigrations is left to the user/deployer
all templates directly in templates folder, like 500.html, login.html, etc
interesting nested app-structure, where some apps are loaded depending on the configuration (i.e. advanced settings.py logic manipulating INSTALLED_APPS)
These make it hard to include the app in urls /suburl/.... I spent 15 minutes thinking this was rewritable, and a git PR would be a good idea, after realizing it might not be.
The most crucial problem, hard coded urls, is in the templates. Hence I want to copy the templates to my parent-project in a subfolder, fix them with generated urls, and redefine template-resolution for this particular app, but not for all apps.
This should keep my template-namespace relatively clean. Also, this way I avoid having to change all the view-functions to specify a better namespaced template. I don't want to get too involved in these, because these functions are massive.
Can I do this, define a customized DjangoTemplates for ONE specific app, but not the others?

Why do trim_blocks and lstrip_blocks under Flask/OpenShift produce different results when tested online, compared when to tested locally?

I'm writing a simple web app using Flask, which is hosted on OpenShift. I want to control whitespace in my template files, with the Jinja command lines essentially removed as in:
<div>
{% if True %}
yay
{% endif %}
</div>
...producing:
<div>
yay
</div>
The Jinja docs at http://jinja2.readthedocs.io/en/latest/templates.html#whitespace-control (and other sources) imply I should do
flask_app_obj.jinja_env.lstrip_blocks = True
flask_app_obj.jinja_env.trim_blocks = True
...which I have done, in my init.py file for my app package. However, this yields inconsistent behaviour when I test locally and then on OpenShift; locally, I get the expected result (i.e. the Jinja commands essentially removed, as if they were never there), and on OpenShift I get:
<div>
YAY
</div>
Consulting the docs and researching similar whitespace issues, it seemed there could be two causes of the inconsistency. Either there is something strange going on with newlines, with my local machine using a different scheme compared to the hosted OpenShift environment (along the lines of https://superuser.com/questions/374028/how-are-n-and-r-handled-differently-on-linux-and-windows) and this produces different whitespace-culling behaviour when the template is generated at the OpenShift end, or, I am changing the Jinja2 environment object when it is shared or after a template has been loaded, which violates the docs which quote:
Instances of this class may be modified if they are not shared and if no template was loaded so far. Modifications on environments after the first template was loaded will lead to surprising effects and undefined behaviour.
... along the lines of Stripping whitespace in jinja2 & flask...why do I still need the minus sign? and Trimming blocks using whitespace control from jinja2 template.
Plausible causes, but I am in doubt they are the reason for the strange OpenShift-side template behaviour. If I had operated on the Jinja environment too early, surely I would see incorrect template output locally as well (which I don't, I get the expected result locally). Indeed, it's in my init.py file that I set lstrip_blocks and trim_blocks to True. I doubt it's a newline issue too since I am developing on OS X, and the OpenShift environment is *nix, so both environments should be using the same newline scheme.
Given the above, I have no more theories as to why I could be getting the inconsistent results between OpenShift testing and local testing. So my questions are these: Have I set the Jinja options in the wrong place and they should be somewhere other than init.py? Am I modifying the Jinja2 Environment inappropriately? Is my method of setting Jinja2 options just plain wrong? Perhaps I should be using some other avenue to set such options other than
flask_app_obj.jinja_env.lstrip_blocks = True
flask_app_obj.jinja_env.trim_blocks = True
Thanks for answering.
If you are using a git push to deploy your code, you might check into having git fix your line endings to be unix/linux style, which is described here: https://help.github.com/articles/dealing-with-line-endings/
Check your version of Jinja2 on OpenShift, it needs to be Version 2.2 or higher.

Python installation doesn't support type of template loading

I've installed Aldryn-boilerplates, using Configuration block's advices from github (https://github.com/aldryn/aldryn-boilerplates#configuration).
But when I make python manage.py runserver I recieve a message:
/home/stp/env/local/lib/python2.7/site-packages/django/template/loader.py:110: UserWarning: Your TEMPLATE_LOADERS setting includes'aldryn_boilerplates.template_loaders.AppDirectoriesLoader', but your Python installation doesn't support that type of template loading. Consider removing that line from TEMPLATE_LOADERS.
warnings.warn("Your TEMPLATE_LOADERS setting includes %r, but your Python installation doesn't support that type of template loading. Consider removing that line from TEMPLATE_LOADERS." % loader)
The web page loads normally (without any template or style).
Also a question, where to put line ALDRYN_BOILERPLATE_NAME = 'bootstrap3'? I've placed it in the bottom of my project's settings.py file.
Anyone knows how to fix that? Or maybe there are another framework with much more detailed description about installation and configuration, which fits for beginners?
I got the some error with django 1.8 and a custom template loader. I had overridden the Loader class out of django.templates.loaders.base. To get rid of this error I also had to the set the class variable is_usable to true
class Myloader(Loader):
is_usable = True
So maybe you can solve your issue with subclassing the 'aldryn_boilerplates.template_loaders.AppDirectoriesLoader' and only change the class variable as shown above.
You have placed the ALDRYN_BOILERPLATE_NAME = 'bootstrap3' at the right place. Please mention the versions of python and django-cms you are using. If you want to try another blogging platform for python, then http://mezzanine.jupo.org/ is helpful for beginners, because it's very easy to setup.

Flask-Assets not working at all... = Insanity

I have simply tried setting up flask-assets (based on webassets), however just can't get it to work.
I have the standard setup;
python virtualenv
pip to install the bare essentials (flask, flask-assets)
sass ruby gem (for trying sass / scss)
less via npm (for trying lesscss)
jsmin via pip (for trying jsmin)
Config:
I have created a working homepage in Flask
static folder created (for css / js assets)
The css / js files are confirmed working (css background, js slider, etc)
Basically my development non-flask-assets site is working perfectly
I have followed the easy official guide here: flask-assets usage.
I fully understand how to work with it (as per that page). I have even exact copy-pasted the code, & still can't get it working.
Some code I've tried (for lesscss): (of course I have working css in main.less)
from flask.ext.assets import Environment, Bundle
assets = Environment(app)
assets.debug = True
lesscss = Bundle('main.less', output='main.css', filters='less')
assets.register('less', lesscss)
Then in my template:
{% assets "less" %}
<link href="{{ ASSET_URL }}" rel="stylesheet">
{% endassets %}
However flask-assets just won't work. I've tried the same with sass, scss, & also jsmin (exact code copy-paste from the usage guide) - it still won't work.
I notice that the .webassets-cache folder is created, but is (always) empty...
Also; relevant error?; I expect it to create the main.css, but as it doesn't, I get an error in the browser (using app.debug = True & flask's built-in dev server):
webassets.exceptions.BuildError
BuildError: Nothing to build for <Bundle output=css/main.css, filters=[<webassets.filter.less.Less object at 0x7f4958dc6710>], contents=('css/main.less',)>, is empty
So; If I manually create an empty main.css, it loads the page (no error), however the main.css file is not filled with css so flask-assets / webassets in still not working.
I've also tried passing the assets object to the template in various ways just in case it's needed (although no documentation states this) - that didn't work.
It's been driving me crazy. Any pointers would be appreciated.
Thank you
There is info missing on the Flask-Assets docs.
You problem is either the sass_bin config or the enviroment load path.
You should try both, in my case it was the config. See below my working config.
PS: IMHO Flask Assets is neither very complete nor well documented. It also consumes you application runtime, which sucks both on debugging and production. I have switched to GULP!
env = Environment(app)
env.config['sass_bin'] = '/usr/local/bin/sass'
# env.load_path = [os.path.join(os.path.dirname(__file__), 'sass')]
js = Bundle('js/jquery/jquery-2.1.4.js', 'js/angular/angular.js',
'js/socketio/socket.io.js', filters='jsmin', output='js/all_min.js')
env.register('js_all', js)
myjs = Bundle('myjs/Interpolation.js', 'myjs/socketio.js' , filters='jsmin', output='myjs/all_min.js')
env.register('myjs_all', myjs)
css = Bundle('sass/base.sass', filters='sass', output='css/base.css')
env.register('css_all', css)

Cannot Extend Django 1.2.1 Admin Template

I am attempting to override/extend the header for the Django admin in version 1.2.1. However when I try to extend the admin template and simply change what I need documented here: http://docs.djangoproject.com/en/dev/ref/contrib/admin/#overriding-vs-replacing-an-admin-template), I run into a recursion problem.
I have an index.html file in my project's templates/admin/ directory that starts with
{% extends "admin/index.html" %}
But it seems that this is referencing the local index file (a.k.a. itself) rather than the default Django copy. I want to extend the default Django template and simply change a few blocks. When I try this file, I get a recursion depth error.
How can I extend parts of the admin? Thanks.
SOLUTION: Rather than extending, I copied the files into my_templates_directory/admin/ and just edited them as I wished. This solution was acceptable, though not ideal.
The contrib/admin/templates/admin path needs to go before the directory with your custom admin templates in your list of paths in TEMPLATE_DIRS in your settings.py
Create a symlink to contrib/admin/templates/admin/ in your templates directory and use it in your {% extends %} statement.
cd /path/to/project/templates/
ln -s /path/to/django/contrib/admin/templates/admin/ django_admin
Now in your admin/index.html use {% extends "django_admin/index.html" %}
EDIT: Just realized that you're on windows... Not sure how to achieve the same results. Hopefully this still helps the folks on linux.
SOLUTION: Rather than extending, I copied the files into my_templates_directory/admin/ and just edited them as I wished. This solution was acceptable, though not ideal.