Monday, September 27, 2010

Re: Path problem in Django admin template

Thanks folks, I did finally manage to get it right.

On Wed, Sep 22, 2010 at 5:46 PM, Nuno Maltez <nuno.lists@gmail.com> wrote:
On Wed, Sep 22, 2010 at 3:57 PM, Sithembewena Lloyd Dube
<zebra05@gmail.com> wrote:
> Hi,
>
> I am having problems with importing tinyMCE javascript files into my admin
> base_site template. I have a media folder with a js fodler in my app as
> follows:
>
> C:\Websites\projectname\appname\media\js\
>
> I want to integrate tinyMCE WYSIWYG editor in my admin app, so I copied the
> base_site.html template from my admin's templates folder and placed it in
>
> C:\Websites\projectname\appname\templates\admin\
>
> In the new base_site template, I have code as follows:
>
> {% block extrahead %}
> <script type="text/javascript"
> src="/{{media_root}}/tiny_mce/tiny_mce.js"></script>

Don't you mean {{MEDIA_URL}} ? media_root gives you a path on the disk
where the files are stored, not the URL from where the files on that
path are served.

>
> The media_root setting in my settings.py file is:
>
> MEDIA_ROOT = os.path.abspath(os.path.dirname('media'))

I'm not sure this is what you want.. See
http://docs.python.org/library/os.path.html#os.path.dirname
on how dirname works. I suppose you'd want something like:

HOME = os.path.abspath(os.path.dirname(__file__)) # get the path for settings.py
MEDIA_ROOT = os.path.join(HOME,'appname/media/')

And you'll probably need to add /js/ to the src="" attribute of the script tag.

Nuno

> <script type="text/javascript">
>     tinyMCE.init({
>     // General options
>             mode : "textareas",
>         theme : "advanced",
>             plugins :
> "safari,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template",
>     // Theme options
>         theme_advanced_buttons1 :
> "save,newdocument,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,styleselect,formatselect,fontselect,fontsizeselect",
>         theme_advanced_buttons2 :
> "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code,|,insertdate,inserttime,preview,|,forecolor,backcolor",
>     theme_advanced_buttons3 :
> "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,media,advhr,|,print,|,ltr,rtl,|,fullscreen",
>     theme_advanced_buttons4 :
> "insertlayer,moveforward,movebackward,absolute,|,styleprops,|,cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,template,pagebreak",
>     theme_advanced_toolbar_location : "top",
>         theme_advanced_toolbar_align : "left",
>         theme_advanced_statusbar_location : "bottom",
>     theme_advanced_resizing : true,
>     });
> </script>
> {% endblock %}

>
> When I run the admin app and view the html source, the media_url is
> truncated as follows:
>
> <script type="text/javascript" src="//tiny_mce/tiny_mce.js"></script>
>
>
> If I start the Python shell in my project, import settings and instantiate
> MEDIA_URL, it appears correct. What am I getting wrong?
> --
> Regards,
> Sithembewena Lloyd Dube
> http://www.lloyddube.com
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscribe@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.




--
Regards,
Sithembewena Lloyd Dube
http://www.lloyddube.com

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

No comments:

Post a Comment