Django-tinymce + django-filebrowser-no-grapelli doesn'work - django

I am confused a bit. I have tried different ways and manuals, but nothing works for me.
What I use: django 1.5, django-page-cms, django-tinymce. I need filebrowser for tinymce for using in admin. I stopped at https://github.com/wardi/django-filebrowser-no-grappelli , becouse it looks simpliest in usage and i don't need Grapeeli, which needs for https://github.com/sehmaschine/django-filebrowser. So I need:
add 'filebrowser' in INSTALLED_APPS;
add (r'^admin/filebrowser/', include('filebrowser.urls')), to urls before admin
change /templates/admin/index.html adding {% include 'filebrowser/append.html' %} before {% for app in app_list %}
After doing those steps and correcting append.html (for django 1.5 - change url look), I receive error Reverse for 'tinymce-filebrowser' with arguments '()' and keyword arguments '{}' not found. when I want enter into the page, where tinymce (and filebrowser) are in usage. Google can't get me certain answer what I need to do.
So I am hope for your help. If anyone has worked with such libraries, can you tell me please, What I need to do in that case? Or is there another working filebrowser exists with the understanding configuration?
UPDATE. After adding tinymce urls and editing almoust all filebrowser templates (becouse of django 1.5). I have some problems:
at the page with tinymce redactor I see in console error: localhost:8000/admin/tinymce/filebrowser/ 404 (NOT FOUND) . tinynce still works fine, but i can't use filebrowser's image-link, which appears after adding filebrowser (error in console: Cannot call method 'apply' of undefined )
uploading of files (directly, without tinymce) always fails here: localhost:8000/admin/filebrowser/upload_file/ 500 (INTERNAL SERVER ERROR)
Any ideas how to solve those problems?
UPDATE. For solving first problem you need put (r'^admin/tinymce/', include('tinymce.urls')), before url(r'^admin/', include(admin.site.urls)),.
For solving second problem you need use right package of django-filebrowser-no-grapelli, preferably where no flash_login_decorator for upload function.

It seems that you have not added django-tinymce urls in urls.py:
(r'^admin/tinymce/', include('tinymce.urls')),

Related

Django "Change Page" loading in strange, single-letter scripts, all with 404 error

This issue is really strange. I am in the Django Admin, updating some data.
The "Change page" loads everything ok at first, but then certain Javascript behaviors aren't behaving properly, so I go to check the Javascript console, and I see 22 errors:
First notice the url (in yellow) of my Admin "Change Page":
and now see all the errors generated from that page (again, notice how the yellow is highlighting the same url as the "Change Page" form above:
Now the strangest part of all:
When I click on the last error, which is:
localhost/:1 Uncaught SyntaxError: Unexpected token <
Instead of showing me source code from the Django Change Page, it shows me markup from one of my Custom Templates instead! That should not be happening!
Any idea what could be going on here?
I figured out the problem.
I had been pulling in jQuery into my Admin Page with the following snippet:
class PageAdmin(admin.ModelAdmin):
# force jquery onto the page
class Media:
js = ('templates/js/vendor/jquery-1.12.2.min.js')
But because this js = () wasn't technically a tuple (it was missing a comma), it was trying to load scripts onto my admin page like this (notice the last letter in the example url is trying to spell out my string in the code snippet above):
example/t
example/e
example/m
example/p
example/l
example/a
example/t
example/e
example/s
example/
...
This is why it was pulling in my custom template, because it was hitting the url example/, which would have loaded in my custom index page.
Mystery solved! I hope this can help someone in the future.

Form Wizard: Correct location for wizard_form.html

I am following the django tutorial on setting up a Form wizard but I am having an issue regarding the location for the template to render the form.
I can see in the documentation that this should be located at formtools/wizard/wizard_form.html
My app is called "survey" so I initially thought to put it inside that
survey/formtools/wizard/wizard_form.html
But I get the error
TemplateDoesNotExist at /contact/
formtools/wizard/wizard_form.html
So then I put it at
survey/contact/formtools/wizard/wizard_form.html
but no change to the error.
I know I could start changeing the WizzardView but I would like to find out what I am doing wrong.
Below is a screenshot of my project structure. Any help is much apriciated.
survey/formtools/wizard/wizard_form.html
You should place this in your templates folder in your survey app

Tastypie Swagger with default configuration gives NoReverseMatch exception, says 'tastypie_swagger' is not a registered namespace

Pretty much as it sounds in the title.
I followed the instructions on https://github.com/concentricsky/django-tastypie-swagger
The install seemed to work, but when I go to the URL I set, I get a "NoReverseMatch at /alex/"
u"'tastypie_swagger" is not a registered namespace
And then a more detailed error that looks like
Error during template rendering
In template /home/vagrant/.virtualenvs/thm/local/lib/python2.7/site-packages/tastypie_swagger/templates/tastypie_swagger/index.html, error at line 48
u"'tastypie_swagger" is not a registered namespace
And shows a line in a tastypie swagger template that is erroring
The main template in tastypie_swagger uses the url tag with a quoted path, as required by Django 1.5, which is incompatible with earlier versions of Django.
Try adding the following to tastypie_swagger/templates/tastypie_swagger/index.html to make it compatible with Django 1.4
(% load url from future %}
Add it anywhere prior to the first {% url %} tag in the file. This should get you past the issue until this can be addressed by the module author.

Error when trying to load Django custom filters into template

I've inherited a Django application that I need to modify using a custom template filter. I'm absolutely new to Django and am quite mystified by it. I thought I had followed the instructions exactly, and also followed all the advice from other posts on the subject, but I still get an error when I include the following line in my template:
{% load mlgb_custom_filters %}
My directory structure is as follows:
mysite (i.e. the project)
__init__.py
mlgb/ (i.e. the app)
__init__.py
templatetags/
__init__.py
mlgb_custom_filters.py
The code of mlgb_custom_filters.py is as follows:
from django import template
from django.template.defaultfilters import stringfilter
register = template.Library()
#register.filter(name='fix_dashes')
#stringfilter
def fix_dashes( value ):
return value.replace( '--', 'DASH' )
if __name__ == "__main__":
testvar = fix_dashes( "ouch -- ow -- I hate django" )
print testvar
As you can see, I've added a 'name = main' section to let me run it in standalone mode, just to check that there are no errors in that particular file, and it's fine when run in standalone mode.
Based on someone else's advice, I've also tried importing it into another file, just to see whether there was an import error, and once again, it was fine if I added this to the end of settings.py (while using the dev server):
try:
import mlgb.templatetags.mlgb_custom_filters
except Exception, exc:
print 'error importing mlgb_custom_filters'
print exc
Also, INSTALLED_APPS in settings.py includes the line 'mysite.mlgb', and I have also tried putting just 'mlgb' instead of 'mysite.mlgb' there, as yet another person suggested. And I restarted the dev server every time I made a change.
I think I have tried every single suggestion that I have found on the web until now. Does anyone have any new ideas? Could it be anything to do with the fact that I have inherited a directory structure where the template directory is not within the same structure as the application, i.e. it is not under mysite? Scraping the barrel for ideas here! I hope someone can help.
OK, in the situation that I was in when first posting this question, it seems all I actually needed to do was touch a wsgi file under my appname/apache directory to force the application to be refreshed. Yesterday's initial answer was a red herring. Basically I should have touched the file myproject/myapp/apache/myapp.wsgi. Then maybe restart Apache for good measure? But the confusion was caused by the fact that apparently it wasn't enough either simply to restart Apache or to manually recompile the Python. In order to pick up my changes, seems like I needed to touch that wsgi file. Then all is well.
I can now post an answer to my own question thanks to the help of my colleague Masud Khokhar, whose brilliant detective work has saved the day. To recap, my application worked fine until I added a 'load' statement to one of my template files, to load a 'custom filters' module. Masud identified that now I needed to use a full/absolute path to the template file in urls.py instead of a relative one as I had before (and which worked before, until it needed to load the custom filters module). So, in urls.py, I had a section of code as follows:
url(r'^book/(?P<object_id>\d+)/$', 'list_detail.object_detail',
kwargs={
'queryset':Book.objects.all(),
'template_name' : 'mlgb/mlgb_detail.html'
},
name='mlgb_detail'
),
Instead of this:
'template_name' : 'mlgb/mlgb_detail.html'
I needed something like this:
'template_name' : '/THE_FULL_PATH/mlgb/templates/mlgb/mlgb_detail.html'
Made that change - sorted! Thank you once again, Masud.

Why is my Django app not displaying dynamic images when the path is correct?

My Django 1.1 app uses dynamic images.
I'm confused about why the path generated from my template tag:
{{image_product.photo.path}}
looks correct, but does not display the requested image.
This generates a path that works:
src='/media/{{image_product.photo}}' => <img src='/media/lcdtvs/product1.jpg'>
This DOES NOT work:
src='{{image_product.photo.path}}' => <img src='/Users/Bryan/work/review_app/media/lcdtvs/product1.jpg'>
I checked to confirm that the Absolute path generated from MEDIA_ROOT is correct on my computer and it works fine.
Why would the image not display correctly?
Two things to keep in mind:
What you want is the {{image_field.url}} method (not the path).
If it still is 404, either you need to setup your server correctly, or if you are using the development server you need to enable it to server static files.
Not familiar with Django, but I'd guess you need to have file:///Users/... in the second snippet.