Fix some bugs

to use the url_for function to generate the urls in templates