简体   繁体   中英

Problems with linking to views in Django

I'm in the process of setting up my views in Django, but I'm confused about how to link it to my pageOne.html page so it shows that instead of the "Welcome" page. Currently, when I run the server using python manage.py runserver 127.0.0.2:8001 I get an error message that says "Template Does Not Exist at" pageOne.html .

I've set

TEMPLATE_DIRS = (os.path.join(os.path.dirname(BASE_DIR), "static", "templates"))

I've also tried

TEMPLATE_DIRS = ('/Users/andrewnguyen/Desktop/Websites/gale/python/techExercise/templates',) 

but that hasn't really worked either.

Update:

Here's a screenshot. I imagine that my error is somewhere in my urls, settings or views.py. I've changed the path to my TEMPLATE_DIRS as mentioned in the comment below. That did not work. I've included an image of my file structure on Imgur: http://imgur.com/kR1xcGJ

Your TEMPLATE_DIRS settings should look like this:

TEMPLATE_DIRS = (
    os.path.join(BASE_DIR, "templates"),
)

Update

After looking at that screenshot you posted, I can say you've made a lot of mistakes.

  1. The templates folder is inside the static folder.

    Move the templates folder out of the static folder.

  2. There's a mistake in the return statement of your view.

It should look like this:

return render(request, 'pageOne.html')

There's no need to prepend /static/templates/ to the template name. Django automatically looks for templates in your settings' TEMPLATE_DIRS path.

And finally, nothing you're doing is very difficult. All these mistakes are caused by ignorance, since everything is mentioned elaborately in the docs. Please read them carefully.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM