Advertisement
Guest User

Untitled

a guest
Feb 10th, 2017
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.67 KB | None | 0 0
  1. <form id="redditor_form">{% csrf_token %}
  2. Name: <input type="text" name="redditor_name" id="redditor_name"> <br />
  3. <input type="submit" value="Submit" />
  4. </form>
  5.  
  6. <script type="text/javascript">
  7. $(document).on('submit','#redditor_form', function(e){
  8. e.preventDefault();
  9. console.log("form submitted!") // sanity check
  10.  
  11. $.ajax({
  12. type: 'POST',
  13. url: 'redditor/search/',
  14. data:{
  15. redditor_name:$('#redditor_name').val(),
  16. csrfmiddlewaretoken:$('input[name=csrfmiddlewaretoken]').val(),
  17. },
  18. success:function(){
  19. alert("it works!");
  20. }
  21. });
  22.  
  23. })
  24. </script>
  25.  
  26. from django.conf.urls import url
  27. from . import views
  28.  
  29. # Create your urls here.
  30. urlpatterns = [
  31. url(r'^$', views.index, name='index'),
  32. url(r'^contact/$', views.contact, name='contact'),
  33. url(r'^redditor/search/$', views.redditor_search, name='redditor_name') #mentioned in the script
  34. ]
  35.  
  36. from django.shortcuts import render
  37. from django.http import HttpResponse
  38.  
  39. def redditor_search(request):
  40. if request.method== 'POST':
  41. redditor_name = request.POST['redditor_name']
  42.  
  43. return HttpResponse('')
  44.  
  45. [webapp1]
  46. client_id=
  47. client_secret=
  48. username=
  49. password=
  50. user_agent= ' '
  51.  
  52. #!/usr/bin/python
  53. import praw
  54.  
  55. reddit = praw.Reddit('webapp1')
  56.  
  57. subreddit = reddit.subreddit("learnpython")
  58.  
  59. for submission in subreddit.hot(limit=5):
  60. print("Title: ", submission.title)
  61. print("Text: ", submission.selftext)
  62. print("Score: ", submission.score)
  63. print("---------------------------------n")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement