Django not recognizing the MEDIA_URL path?

前端 未结 8 1838
鱼传尺愫
鱼传尺愫 2021-02-03 13:23

So I\'m trying to get TinyMCE up and running on a simple view function, but the path to the tiny_mce.js file gets screwed up. The file is located at /Users/home/Django/tinyMCE/m

相关标签:
8条回答
  • 2021-02-03 14:04

    I was also having the same problem, this is how I got it done.

    If you are using a FileField in your model class instead of MEDIA_URL use .url member to access the url of your file. For eg: something like this

    href = "{{ some_object.file_name.url }}" 
    

    here file_name is the FileField in model class.

    0 讨论(0)
  • 2021-02-03 14:08

    You can either pass it to the template manually as others have suggested or ensure that you are using a RequestContext instead of plain Context. RequestContext will automatically populate the context with certain variables including MEDIA_URL and other media-related ones.

    Example from docs:

    def some_view(request):
        # ...
        return render_to_response('my_template.html',
                                  my_data_dictionary,
                                  context_instance=RequestContext(request))
    
    0 讨论(0)
提交回复
热议问题