0

So guys as you read earlier i'm working on the RSS Fedd in the django. i've done all the code but when i'm enter the url for any feed it gives me and error related that saying your code giving the None instead of HttpResponse and i don't know how to solve this please Help me. any help would be appricated.

MY HTML CODE IS for BASE HTML==

<!DOCTYPE html>
<head>
   <title>Django RSS Reader</title>
   <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"></script>
   <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js"></script>
   <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.2/js/bootstrap.min.js"></script>
   <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.2/css/bootstrap.min.css">
</head>
<nav class="navbar navbar-expand-sm bg-dark navbar-dark">
   <ul class="navbar-nav">
      <li class="nav-item active">
         <a class="nav-link" href="/">Home</a>
   </ul>
</nav>
<body>
   {% block content %}
   {% endblock %}
</body>
</html>

MY HTML CODE FOR READER.HTML PAGE

{% extends 'reader/base.html' %}
{% block content %}
<br/>
<form class="form-inline">
   <div class="form-group mx-sm-3 mb-2">
      <label for="inputPassword2" class="sr-only">Password</label>
      <input type="text" class="form-control" placeholder="paste link" name="url">
   </div>
   <button type="submit" class="btn btn-primary mb-2">Search</button>
</form>
{% if feed %}
<h2>{{ feed.feed.title }}</h2>
{% if feed.entries %}
{% for entry in feed.entries %}
<div class="card">
   <div class="card-header">
      Feed
   </div>
   <div class="card-body">
      <h5 class="card-title">Headline: {{ entry.title }}</h5>
      <p class="card-text">Description: {{ entry.description }}</p>
      <a href="{{ entry.link }}" class="btn btn-primary">Visit Link</a>
   </div>
</div>
<p>{{ entry.published }}</p>
{% endfor %}
{% endif %}
{% else %}
<br/>
<p>Enter your favorite RSS feed above.</p>
{% endif %}
{{ feed2 }}
{% endblock %}

MY URL CODE

from django.contrib import admin
from django.urls import path,include
from reader.feeds import LatestEntriesFeed
urlpatterns = [
    path('admin/', admin.site.urls),
    path('', include('reader.urls')),
    path(r'feed/', LatestEntriesFeed()),
]

MY VIEWS CODE

from django.shortcuts import render
from django.http import HttpResponse

# Create your views here.
import feedparser

def index(request):
    if request.GET.get('url'):
        url = request.GET['url'] #Getting URL
        feed = feedparser.parse(url) #Parsing XML data
    else:
        feed = None
        return render(request, 'reader/reader.html', {'feed' : feed,})


Encaledus
  • 51
  • 9

1 Answers1

0

i think you need to move the return out of else block so the function can return some thing if the if block passed.

def index(request):

    if request.GET.get('url'):
        url = request.GET['url'] #Getting URL
        feed = feedparser.parse(url) #Parsing XML data
    else:
        feed = None

    # HERE
    return render(request, 'reader/reader.html', {'feed' : feed,})
cizario
  • 3,995
  • 3
  • 13
  • 27