Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8527253
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T08:30:16+00:00 2026-06-11T08:30:16+00:00

I followed this article to try to load images from an external website. I

  • 0

I followed this article to try to load images from an external website. I am trying to pull all the images from an external link. I have used BeautifulSoup to parse the link and get all the required links.

Before the view calls the render() function at the end of the code, image_list and return_dict have the desired values. However the render function seems to be generating the AttributeError exception. Please assist.

I get the following error:

    AttributeError at /post/add_new/
    META
    Request Method: POST
    Request URL:    http://localhost:8000/post/add_new/
    Django Version: 1.4.1
    Exception Type: AttributeError
    Exception Value:    
    META
    Exception Location: C:\Python27\lib\urllib2.py in __getattr__, line 225
    Python Executable:  C:\Python27\python.exe
    Python Version: 2.7.3
    Python Path:    
    ['C:\\Users\\Talal\\Python Workspace\\talal_ynd',
     'C:\\Python27\\lib\\site-packages\\ipython-0.13-py2.7.egg',
     'C:\\Python27\\lib\\site-packages\\pyreadline-2.0_dev1-py2.7-win32.egg',
     'C:\\Python27\\lib\\site-packages\\pil-1.1.7-py2.7-win32.egg',
     'C:\\Python27\\lib\\site-packages\\setuptools-0.6c11-py2.7.egg',
     'C:\\windows\\system32\\python27.zip',
     'C:\\Python27\\DLLs',
     'C:\\Python27\\lib',
     'C:\\Python27\\lib\\plat-win',
     'C:\\Python27\\lib\\lib-tk',
     'C:\\Python27',
     'C:\\Python27\\lib\\site-packages']
    Server time:    Thu, 13 Sep 2012 17:30:45 +0500

Here is my view file:

# Create your views here.
from django.shortcuts import render
from django.http import HttpResponseRedirect
from posts.models import Post, PostForm
from django.template.loader import get_template
from talal_ynd.settings import TEMPLATE_DIRS


def post_view(request):
    if request.method == 'POST':
        post_form = PostForm(request.POST)
        if post_form.is_valid():
            success_message = 'Thank you.'

            link = post_form.cleaned_data['link']
            if 'get_link' in request.POST:
                import urllib2
                request = urllib2.Request(link)
                response = urllib2.urlopen(request)
                html=response.read()
                from BeautifulSoup import BeautifulSoup
                soup=BeautifulSoup(html)
                import re
                title=''; description=''
                description=soup.findAll('meta',
                    attrs={'name':re.compile("description$",
                        re.I)})[0].get('content')
                try: 
                    title=soup.findAll('meta',
                        attrs={'name':re.compile("^title$",re.I)})[0].get('content')
                except:
                    pass
                if not title:
                    title=soup.title.string
                max_images=10
                image_tags=soup.findAll('img',limit=max_images)
                image_urls_list=[]
                image_urls_list2=[]
                from urlparse import urljoin
                for image_tag in image_tags:
                    url=image_tag.get('src')
                    #image_urls_list.append(request.build_absolute_uri(url))#urljoin(link,url))#HttpRequest.build_absolute_uri(url))
                    #image_urls_list.append(request.urljoin(link,url))
                    image_urls_list.append(url)
                image_list=[]
                for url in image_urls_list:
                    image_list.append({'url':url})
                return_dict={'title':title, 'description':description}
                return_dict.update({'images':image_list})

            else:
                post_form = PostForm()
    else:

        post_form = PostForm()


    return render(request, 'posts/post_form.html', locals())
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T08:30:18+00:00Added an answer on June 11, 2026 at 8:30 am

    You’ve overwritten the request variable inside your function, because you reused it for the call to urllib2.Request. Use a different variable name there.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have followed this article and implemented my service and I can open the
I followed this link to gzip my php driven website It's working fine but
i have an issue trying to generate rss. I followed all the steps of
I have followed this tutorial http://blogs.wrox.com/article/creating-a-simple-ipad-application-table-view/ (creating a uitableview and populating it). I want
Since I followed this article to implement a theme engine in Asp.net MVC website.
I followed this tutorial http://www.vogella.com/articles/AndroidCloudToDeviceMessaging/article.html I wrote the manifest File giving all the permissions
I followed this tutorial and got the basics of Content Providers : http://www.vogella.de/articles/AndroidSQLite/article.html But
I've followed the instructions in this MSDN article: http://msdn.microsoft.com/en-us/library/dd206945.aspx Is it possible to call
I followed this tutorial . But whenever I try to log in with my
I followed this tutorial to implement facebook into my application. All I want is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.