Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <form id="redditor_form">{% csrf_token %}
- Name: <input type="text" name="redditor_name" id="redditor_name"> <br />
- <input type="submit" value="Submit" />
- </form>
- <script type="text/javascript">
- $(document).on('submit','#redditor_form', function(e){
- e.preventDefault();
- console.log("form submitted!") // sanity check
- $.ajax({
- type: 'POST',
- url: 'redditor/search/',
- data:{
- redditor_name:$('#redditor_name').val(),
- csrfmiddlewaretoken:$('input[name=csrfmiddlewaretoken]').val(),
- },
- success:function(){
- alert("it works!");
- }
- });
- })
- </script>
- from django.conf.urls import url
- from . import views
- # Create your urls here.
- urlpatterns = [
- url(r'^$', views.index, name='index'),
- url(r'^contact/$', views.contact, name='contact'),
- url(r'^redditor/search/$', views.redditor_search, name='redditor_name') #mentioned in the script
- ]
- from django.shortcuts import render
- from django.http import HttpResponse
- def redditor_search(request):
- if request.method== 'POST':
- redditor_name = request.POST['redditor_name']
- return HttpResponse('')
- [webapp1]
- client_id=
- client_secret=
- username=
- password=
- user_agent= ' '
- #!/usr/bin/python
- import praw
- reddit = praw.Reddit('webapp1')
- subreddit = reddit.subreddit("learnpython")
- for submission in subreddit.hot(limit=5):
- print("Title: ", submission.title)
- print("Text: ", submission.selftext)
- print("Score: ", submission.score)
- print("---------------------------------n")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement