0

I'm testing a django site on the local server: http://127.0.0.1:8000/

The sites internal links all work great, even the static links. However, when I try to link to an outside link with say <a href="http://google.com">google</a> as text inside a text field of my blog model it doesnt render the link correctly. That blog model is then passed through as |safe (so that the html is rendered) to the template, and the link is instead trying to append everything to the static root:

http://127.0.0.1:8000/blog/view/http://google.com

Anyone know how to keep my static links working, but still have links that go outside of the site?

EDIT: For example, here is a blog post that is stored in a TextField() from the admin, inside my blog app. The blog post has some links. The link to the /static/mytextfile works fine as it appends that to the http://127.0.0.1:8000/. However, the github link isnt working as it attempts to append the github link to http://127.0.0.1:8000/ and thus the outputted html creates "http://127.0.0.1:8000/http://github.com/":

<p><b>The Code</b><br>
<a href=”http://github.com/”>GitHub</a>

<p><b>Example Outputs</b>
<br><a href="/static/mytextfile.txt">a text file</a>

Here's the 404 error that I get:

Page not found (404)
Request Method: GET
Request URL:    http://127.0.0.1:8000/blog/view/%E2%80%9Dhttp://github.com/%E2%80%9D

EDIT 2:

This is how I have been 'escaping' the html filter. Up until now it has worked fine at leaving my <p> etc alone. It is not however leaving my href links alone!

{% autoescape off %}
{% block content %}
    <p>{{ post.body|safe }}</p>
{% endblock %}
{% endautoescape %}
InfinteScroll
  • 664
  • 3
  • 11
  • 24
  • Can you paste the code here - I suspect your description of the problem is not accurate, since your example uses http and https for the Google URL – Matt Healy Feb 14 '14 at 05:04

2 Answers2

2

Something seems to be wrong with your double quote characters for the GitHub link.

Instead of:

<p><b>The Code</b><br>
<a href=”http://github.com/”>GitHub</a>

Try:

<p><b>The Code</b><br>
<a href="http://github.com/">GitHub</a>
Matt Healy
  • 18,033
  • 4
  • 56
  • 56
  • okay you are definitely on the right track! That 404 error I was getting was showing %E2%80%9D which I guess are those weird quotes. I went back in to edit the quotes. They look normal now in the TextField(), but when I view the blog post and inspect the element it's rendering: github which is definitely not what I typed in. My other HTML is rendering just fine, any idea why the links are throwing me off? – InfinteScroll Feb 14 '14 at 05:58
  • This is what I do to normally escape the HTML, but for some reason the – InfinteScroll Feb 14 '14 at 06:01
  • How exactly do you escape the HTML? – Matt Healy Feb 14 '14 at 06:03
  • http://stackoverflow.com/questions/2080559/disable-html-escaping-in-djangos-textfield – InfinteScroll Feb 14 '14 at 06:14
  • 1
    I finally got it. The quotes werent "the right kind" of double quotes as you pointed out. as soon as I fixed that and added in http:// prefixes it realized that I wasnt looking for relative paths. – InfinteScroll Feb 14 '14 at 06:32
0

I think you should try <a href="http://www.google.com">google</a>.

Paul
  • 6,641
  • 8
  • 41
  • 56