Я работаю над веб-сайтом, используя Django, я новичок в Jquery, и я пытаюсь отобразить изображение, используя JQuery, когда форма отправлена. Изображение не отображается, и я получаю сообщение об ошибке в консоли "Undefined".
![enter image description here](https://i.stack.imgur.com/1nJpC.jpg)
![enter image description here](https://i.stack.imgur.com/BOLmy.jpg)
JQuery:
var chatHolder = $('#chat-items')
// below is the message I am receiving
socket.onmessage = function(e) {
var chatDataMsg = JSON.parse(e.data)
var profile_pic = $('#avatarImg').attr("src");
console.log(profile_pic);
chatHolder.append("" + "
![image](+ profile_pic +)
" + "
" + "
" + "
" + chatDataMsg.message + "
" + "
" + "
" + newMonth + newDate + "" + "
" + "
" + "")
}
Template:
{% для чата в object.chatmessage_set.all%} {% if request.user! = chat.user%}
![image]({{ chat.user.profile.profile_pic.url }})
{{chat.message | emoticons}} {{chat.timestamp | date: 'M j, Y, g: ia'}} {% endif%} {% endfor%} {% csrf_token%} {{form}}