How to render a Matplotlib plot in a Django web application?

后端 未结 1 1579
盖世英雄少女心
盖世英雄少女心 2020-12-19 18:41

I\'m reading the book Matplotlib for Python Developers but am struggling to follow the example in the section \"Matplotlib in a Django application\" in chapter 8.

So

相关标签:
1条回答
  • 2020-12-19 19:17

    According to cannot import name patterns this is indeed a legacy interface of Django. I 'updated' it by making mpldjango/urls.py as follows:

    from django.conf.urls import include, url
    from django.contrib import admin
    import mpl.views
    
    urlpatterns = [
        url(r'^admin/', admin.site.urls),
        url(r'mplimage.png', mpl.views.mplimage),
    ]
    

    Now if I browse to http://localhost:8000/mplimage.png I see the plot as desired:

    0 讨论(0)
提交回复
热议问题