python django call chat.py in template $ajax ? giving error not found
<p>hi i am new at python django.
i have template where i wana call a file through ajax</p>

<pre><code> $.ajax({
    type: "POST",
    url: "chat.py",
    data: {foo: 'bar', bar: 'foo'},
</code></pre>

<p>and <code>urls.py</code></p>

<pre><code>from django.conf.urls import include , url
from . import views
from . import chat

urlpatterns = [
    url(r'^$', views.index, name='index'),

  url(r'^$', chat.main, name='main'),
]
</code></pre>

<p>and <code>chat.py</code></p>

<pre><code>import os
import sys

sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
sys.path.append("../../tf_seq2seq_chatbot_parent")
import tensorflow as tf

from tf_seq2seq_chatbot.lib.chat import chat


def main(_):
    #chat()
    print('kjgjkh')

if __name__ == "__main__":
    tf.app.run()
</code></pre>

<p>and <code>views.py</code></p>

<pre><code>from django.shortcuts import render
def index(request):
    return render(request , "base.html" , {})

error: poll/chat.py not found
</code></pre>

<p>You haven't got a URL "chat.py". Your URLs are defined in the regexes in your urls.py; but you've only defined one, which is just /, although you've defined it twice which can't possibly work.</p>

<p>Make those two URLs different, and use the one you want in your Ajax call.</p>

python ajax django