0

I want to use this pluggin for watermarking images in my django website. After following the instruction I made it work in plain html server (wampserver) after trying it in my django environment, it's not working.

HTML (wampserver)

html lang="en">
<title>cool</title>
<head>


<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"  type="text/javascript"></script>
<script type="text/javascript" src="js/jquery-1.7.1.min.js"></script>


</head>
<body>
<script type="text/javascript" src="js/watermark.jquery.js"></script>
<script type="text/javascript" src="js/watermark.jquery.min.js"></script>
    <script language="javascript">
    var config = {
        "path": "images/watermark.png"};
     $(document).ready(function() {
     $(document).watermark(config);
    });
</script>

    <img src="images/hall1.jpg" alt="" class="watermark"/>
    <img src="images/hall3.jpg" alt="" title="This is an example of a caption" class="watermark"/>
    <img src="images/main.jpg" alt="" class="watermark"/>


</body>
</html>

The above code is working fine.

Django Environment(Not working)

  </head>
  <body>    
   <script type="text/javascript" src="{{MEDIA_URL}}/css/watermark.jquery.js"></script>
   <script type="text/javascript" src="{{MEDIA_URL}}/css/watermark.jquery.min.js"></script>
    <script language="javascript">
    var config = {
        "path": "/media/css/watermark.png" };
     $(document).ready(function() {
     $(document).watermark(config);
    });
  </script>

  <li><img src="{{ MEDIA_URL }}/{{post.main}}" class="watermark"/> </li>
  <li><img src="{{ MEDIA_URL }}/{{post.side}}" class="watermark"/> </li>
  <li><img src="{{ MEDIA_URL }}/{{post.sitting}}" class="watermark"/> </li>

  </body>

How can I fix this issue?

3
  • check the network tab of your browser to see the actual location of the file being requested Commented Mar 23, 2013 at 9:03
  • stackoverflow.com/questions/15081893/… Commented Mar 23, 2013 at 13:03
  • There is no reason to load jQuery and the jQuery plugin twice! Once is enough. Commented Mar 24, 2013 at 0:46

1 Answer 1

0

If you want to address your static files like your css/js files, Then you have to use STATIC_URL.

   <script type="text/javascript" src="{{ STATIC_URL }}/css/watermark.jquery.js"></script>
   <script type="text/javascript" src="{{ STATIC_URL }}/css/watermark.jquery.min.js"></script>

So the same way will be used for watermark.png path:

"path": "{{ STATIC_URL }}/css/watermark.png"

Also consider that MEDIA_ROOT where you can refer to it with MEDIA_URL is absolute filesystem path to the directory that will hold user-uploaded files is not a right place for your assets, You should config it correctly then you will be able to address them by STATIC_URL.

For more on this topic:

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.