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

  • Home
  • SEARCH
  • 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 914487
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T17:43:34+00:00 2026-05-15T17:43:34+00:00

I want to check in django if a URL exists and if it does

  • 0

I want to check in django if a URL exists and if it does I want to show something on screen, i.e.:

if URL_THAT_POINTS_TO_SOME_PDF exists 
     SHOW_SOMETHING
  • 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-05-15T17:43:34+00:00Added an answer on May 15, 2026 at 5:43 pm

    Edit: Please note, this is no longer valid for any version of Django above 1.5

    I assume you want to check if the file actually exists, not if there is just an object (which is just a simple if statement)

    First, I will recommend always looking through Django’s source code because you will find some great code that you could use 🙂

    I assume you want to do this within a template. There is no built-in template tag to validate a URL but you could essentially use that URLValidator class within a template tag to test it. Simply:

    from django.core.validators import URLValidator
    from django.core.exceptions import ValidationError
    
    validate = URLValidator(verify_exists=True)
    try:
        validate('http://www.somelink.com/to/my.pdf')
    except ValidationError as e:
        print(e)
    

    The URLValidator class will spit out the ValidationError when it can’t open the link. It uses urllib2 to actually open the request so it’s not just using basic regex checking (But it also does that.)

    You can plop this into a custom template tag, which you will find out how to create in the django docs and off you go.

    Hope that is a start for you.

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

Sidebar

Related Questions

I don't want check if an item with a value exists in the arraylist,
As part of a form validation in Django, I want to check when a
I'm writing a quick Django module and want to check for another module. Is
I have a list in my Django template. I want to do something only
I want to check the useragent using Django inside my template. I know this
I want to check if a value belongs to a list in django template.
After login user should be redirected to the ?next=%s url. I want to check
I want to check which port is used, when the port is not explicitly
I want to check checkbox like $('#riderCheck').attr('checked','true') on some condition. but the problem is
I want to check if my many column in datagridview is empty. here my

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.