简体   繁体   中英

How to resolve the django import from view function?

On my way to learn django, I have been following this book

My views.py contains -

def addPublisher(request):
    if request == 'POST':
        form = PublisherForm(request.POST)
        if form.is_valid:
            form.save()
            return HttpResponseRedirect('add_publisher/thanks/')
        else:
            form = PublisherForm()
        return render_to_response('book/addPublisher.html',{'form':form})

My urls.py has following code-

from views import *

urlpatterns = [
    url(r'^add/$',addPublisher)
    ]

While importing addPublisher function to my urls.py, I am getting this error.

name 'addPublisher' is not defined

Your urls.py file is probably not in the same app (folder) than your views.py. You are getting this error saying that addPublisher is not defined because it's literally not there , by there I mean the app where urls.py is located.

If that particular views.py above is located in another app, please import it with something like

from [name of app].views import *

Anyway, showing us the layout of your project will help us give you a more direct and specific answer! Thank you.

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