Giter Site home page Giter Site logo

Comments (3)

adi- avatar adi- commented on May 23, 2024

There is no easy way to do it "quick", I think. You could change JS script a bit to be able to send images. This should be a simple change.

from django-markdownx.

agusmakmun avatar agusmakmun commented on May 23, 2024

How i can do it? can u give me an example?

from django-markdownx.

agusmakmun avatar agusmakmun commented on May 23, 2024

Finally i got it.. 😄

Inside file of dummy.html

<script src="/static/suit/js/jquery-1.8.3.min.js"></script>

<form enctype="multipart/form-data" method="POST" action=".">{% csrf_token %}
  {{ form.image }}
</form>

<script>
    // CSRF code
    function getCookie(name) {
        var cookieValue = null;
        var i = 0;
        if (document.cookie && document.cookie !== '') {
            var cookies = document.cookie.split(';');
            for (i; i < cookies.length; i++) {
                var cookie = jQuery.trim(cookies[i]);
                // Does this cookie string begin with the name we want?
                if (cookie.substring(0, name.length + 1) === (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }

    // Uploading the image if on change.
    $('input[name=image]').on('change', function(evt) {
      evt.preventDefault();
      var formData = new FormData($('form').get(0));
      formData.append("csrfmiddlewaretoken", getCookie('csrftoken'));

      $.ajax({
          url: '/markdownx/upload/',
          type: 'POST',
          data: formData,
          async: true,
          cache: false,
          contentType: false,
          enctype: 'multipart/form-data',
          processData: false,
          beforeSend: function() {
              console.log("uploading...");
          },
          success: function (response) {
              console.log(response['image_code']);
          },
          error: function(response) {
              console.log("error", response);
          }
      });
      return false;
    });
</script>

from django-markdownx.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.