Forums

Django - URLField

Hi PythonAnywhere-ers,

I'm having a problem with a Django model. There's a model field known as URLField, which has a method .verify_exists. Basically this function checks that the URL exists when the instance is saved. Unfortunately, when the site is live, any URL I enter in the admin site will not save, even definitely real URLs like my own site, Google or PythonAnywhere.

There isn't a problem with the code in, e.g. models.py or admin.py, because it works when it's running locally on my machine (i.e. 127.0.0.1:8000/admin/ ), provided I'm connected to the internet. So, I'm wondering, is this something PythonAnywhere is blocking? Or am I missing some magick setting somewhere?

Appreciate the help,

Phophos.

[Edited to remove reference to non-existent bug on our side and explain Django oddity/bug]

Hi Phophos,

That sounds like it's a result of two problems:

  • Internet access is restricted for free accounts, so your web app will only be able to access sites that we've explicitly whitelisted. (We had to do that recently, much as we wished we didn't, after a number of cases where people were using PythonAnywhere free accounts to do bad things.) This happens via an http/https proxy; the proxy configuration environment variables are passed in to your web app when it starts up.
  • The code inside Django that does the URL verification ignores proxy settings, so when it tries to verify the URL, it just gets blocked.

Unfortunately this means that there are really only two solutions:

  • If you just want your admin site to be able to save URLs and don't mind it not verifying, then you can set verify_exists to False. I guess you knew that ;-)
  • If you want your admin site to be able to verify any URL at all, then you'll need to upgrade to a non-free account -- the $5/month Premium one has unrestricted internet access, and the $9/month Hosting one throws in the ability to use your own domain too.

Hope that helps!

Giles

Hi Giles,

Thanks for the reply. I shall opt for the first for the moment - since I'm manually inputting URLs that I know to be real, this won't be a problem.

Cheers,

Phophos.

Sounds good, please do let us know if you have any other problems!

Giles