I'm new to Django. Please help me with the below.
I have a User form who provides URL1 and URL2.. These URLs need to be passed to another Python script[redirects.py
] which will do the Validation to check whether they are in a valid URL format and return the Message to the User.
Now my question is how to write my views.py
so as to get this done. I got to know that we can import the redirects.py
in my views.py
and call it. But I'm not aware of how to print the messages in my browser. Please help. Let me know if any more info is required.
def shortcuts_process(request):
print request.POST
return HttpResponse("Source is %s\nDestination is %s" % (request.POST['source'],request.POST['destination']))
Update :
This is my script overview. I have got a python script[redirects.py
] in my system which accepts Source and Destination URLs. Once accepted, it validates whether they are in URL format, then takes backup, then add them into .htaccess
and display the line added to the file. While doing all this, it keeps intimating the User with the information on whats happening in the script.
Now I have made the django to create a web portal which provides the User to input source and Destination. Now i want to call the script from views.py
and print all those redirects.py
Script output in User's web browser.
Please help me in getting this, I have spent an entire day looking for this answer. Thanks.
Update 2:
Please let me know why the below is not getting displayed in my browser
From views.py
def shortcuts_process(request):
if 'source' in request.POST and 'destination' in request.POST and request.POST['source'] and request.POST['destination']:
src=request.POST['source']
desti= request.POST['destination']
my_result=process_input(src,desti)
return render_to_response('results.html',{'result': my_result}
From results.html
:
<html>
<head>
This is the result page to User
</head>
<body>
<ul>
{% for each_line in result %}
<p>{{ each_line }}</p>
{% endfor %}
</ul>
<p>
I'm supposed to be printed</p>
</body>
</html>
From browser output :
This is the result page to User
I'm supposed to be printed
From Linux prompt :
[10/Jun/2013 04:41:11] "GET /redirects HTTP/1.1" 200 727 [10/Jun/2013 04:41:14] "GET /choice?selection=shortcuts HTTP/1.1" 200 817 The URL is not in the right format The URL is not in the right format [10/Jun/2013 04:41:18] "POST /shortcuts.conf HTTP/1.1" 200 125
So now my question, why the Message The URL is not in the right format
is not getting displayed on browser rather it displays in Linux prompt. Please help. Thanks
def shortcuts_process(request): if 'source' in request.POST and 'destination' in request.POST and request.POST['source'] and request.POST['destination']: result=take_backup() return render_to_response('result.html', {'result':result})
But I could not see any result in my browser. Rather I can see the information in the Linux prompt[whilst running the manage.py runserver] – Sathy Jun 10 at 3:14