How to connect python file and HTML page in Django [on hold]











up vote
-1
down vote

favorite












I am working on Django and already open a project according to guide from their site.
Now I have the project and when I start it on anaconda prompt I can see it on localhost:8000.
(I run these lines- pipenv shell , python manage.py runserver)
it shows me the content of template of HTML page name it works.
I want to try the opportunity of sending mail in Gmail in python.
I want to make HTML file that has a button that if it clicked email will send.
I have the code to send mail but I'm not sure how to connect HTML page to python file and how do I represent it in the localhost.
Thanks










share|improve this question









New contributor




python_Code is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











put on hold as unclear what you're asking by Klaus D., legoscia, greg-449, Rob, GhostCat 14 hours ago


Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.















  • What have you tried so far? Do you get any errors? Can you show us a piece of your code?
    – Adi
    17 hours ago















up vote
-1
down vote

favorite












I am working on Django and already open a project according to guide from their site.
Now I have the project and when I start it on anaconda prompt I can see it on localhost:8000.
(I run these lines- pipenv shell , python manage.py runserver)
it shows me the content of template of HTML page name it works.
I want to try the opportunity of sending mail in Gmail in python.
I want to make HTML file that has a button that if it clicked email will send.
I have the code to send mail but I'm not sure how to connect HTML page to python file and how do I represent it in the localhost.
Thanks










share|improve this question









New contributor




python_Code is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











put on hold as unclear what you're asking by Klaus D., legoscia, greg-449, Rob, GhostCat 14 hours ago


Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.















  • What have you tried so far? Do you get any errors? Can you show us a piece of your code?
    – Adi
    17 hours ago













up vote
-1
down vote

favorite









up vote
-1
down vote

favorite











I am working on Django and already open a project according to guide from their site.
Now I have the project and when I start it on anaconda prompt I can see it on localhost:8000.
(I run these lines- pipenv shell , python manage.py runserver)
it shows me the content of template of HTML page name it works.
I want to try the opportunity of sending mail in Gmail in python.
I want to make HTML file that has a button that if it clicked email will send.
I have the code to send mail but I'm not sure how to connect HTML page to python file and how do I represent it in the localhost.
Thanks










share|improve this question









New contributor




python_Code is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











I am working on Django and already open a project according to guide from their site.
Now I have the project and when I start it on anaconda prompt I can see it on localhost:8000.
(I run these lines- pipenv shell , python manage.py runserver)
it shows me the content of template of HTML page name it works.
I want to try the opportunity of sending mail in Gmail in python.
I want to make HTML file that has a button that if it clicked email will send.
I have the code to send mail but I'm not sure how to connect HTML page to python file and how do I represent it in the localhost.
Thanks







python django






share|improve this question









New contributor




python_Code is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question









New contributor




python_Code is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question








edited 17 hours ago





















New contributor




python_Code is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked 18 hours ago









python_Code

11




11




New contributor




python_Code is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





python_Code is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






python_Code is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




put on hold as unclear what you're asking by Klaus D., legoscia, greg-449, Rob, GhostCat 14 hours ago


Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.






put on hold as unclear what you're asking by Klaus D., legoscia, greg-449, Rob, GhostCat 14 hours ago


Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.














  • What have you tried so far? Do you get any errors? Can you show us a piece of your code?
    – Adi
    17 hours ago


















  • What have you tried so far? Do you get any errors? Can you show us a piece of your code?
    – Adi
    17 hours ago
















What have you tried so far? Do you get any errors? Can you show us a piece of your code?
– Adi
17 hours ago




What have you tried so far? Do you get any errors? Can you show us a piece of your code?
– Adi
17 hours ago












1 Answer
1






active

oldest

votes

















up vote
0
down vote













If you have a python file you need to run on the server side to send the email, you can use an anchor tag: <a href="{% url 'send_email_view_url' %}">Send Email</a> in your html template and define a view in your views.py file that does something similar to



def send_email_view(request, *args, **kwargs):
#send email function here
return HttpResponseRedirect('url_for_redirect')


You can set url_for_redirect to the original page.



Something tells me this is not best practice though. If you needed to do it on the server side, I'd do it with .ajax() in jQuery or Javascript, but you seem to just be getting into django so I don't wanna bother you with that






share|improve this answer




























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    0
    down vote













    If you have a python file you need to run on the server side to send the email, you can use an anchor tag: <a href="{% url 'send_email_view_url' %}">Send Email</a> in your html template and define a view in your views.py file that does something similar to



    def send_email_view(request, *args, **kwargs):
    #send email function here
    return HttpResponseRedirect('url_for_redirect')


    You can set url_for_redirect to the original page.



    Something tells me this is not best practice though. If you needed to do it on the server side, I'd do it with .ajax() in jQuery or Javascript, but you seem to just be getting into django so I don't wanna bother you with that






    share|improve this answer

























      up vote
      0
      down vote













      If you have a python file you need to run on the server side to send the email, you can use an anchor tag: <a href="{% url 'send_email_view_url' %}">Send Email</a> in your html template and define a view in your views.py file that does something similar to



      def send_email_view(request, *args, **kwargs):
      #send email function here
      return HttpResponseRedirect('url_for_redirect')


      You can set url_for_redirect to the original page.



      Something tells me this is not best practice though. If you needed to do it on the server side, I'd do it with .ajax() in jQuery or Javascript, but you seem to just be getting into django so I don't wanna bother you with that






      share|improve this answer























        up vote
        0
        down vote










        up vote
        0
        down vote









        If you have a python file you need to run on the server side to send the email, you can use an anchor tag: <a href="{% url 'send_email_view_url' %}">Send Email</a> in your html template and define a view in your views.py file that does something similar to



        def send_email_view(request, *args, **kwargs):
        #send email function here
        return HttpResponseRedirect('url_for_redirect')


        You can set url_for_redirect to the original page.



        Something tells me this is not best practice though. If you needed to do it on the server side, I'd do it with .ajax() in jQuery or Javascript, but you seem to just be getting into django so I don't wanna bother you with that






        share|improve this answer












        If you have a python file you need to run on the server side to send the email, you can use an anchor tag: <a href="{% url 'send_email_view_url' %}">Send Email</a> in your html template and define a view in your views.py file that does something similar to



        def send_email_view(request, *args, **kwargs):
        #send email function here
        return HttpResponseRedirect('url_for_redirect')


        You can set url_for_redirect to the original page.



        Something tells me this is not best practice though. If you needed to do it on the server side, I'd do it with .ajax() in jQuery or Javascript, but you seem to just be getting into django so I don't wanna bother you with that







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered 17 hours ago









        robotHamster

        13011




        13011















            Popular posts from this blog

            Xamarin.iOS Cant Deploy on Iphone

            Glorious Revolution

            Dulmage-Mendelsohn matrix decomposition in Python