[Fixed]-Django html onclick to open another html page

1đź‘Ť

You haven’t provided your full app layout so this is a bit hard to answer, but it sounds like you have a views folder containing a file “batterycurrent.py”, which in turn contains your view BatteryCurrentView.

If so, as well as ensuring that you have an (empty) __init__.py file in that directory, you urls.py needs to import the view from the module it is in:

from views.batterycurrent import BatteryCurrentView

Also, I don’t understand what you are doing with sub_urlpatterns in that file. You don’t define that dictionary anywhere; but in any case, the patterns must be in a list called just urlpatterns.

Finally, ensure that that file is actually called urls.py, not url.py.

0đź‘Ť

Seems like the problem is in import the module in url.py file.

If you have created BatteryCurrentView module inside the batterycurrent.py and your url.py file in the different folder then you need to import your module through the name of the folder with the file name.

So Your file is inside the view folder then you should use

from views.batterycurrent import BatteryCurrentView

And if in case your file url.py resides in the same folder inside view then you need to just import module like this:

from .batterycurrent import BatteryCurrentView
👤Ahmed Ginani

0đź‘Ť

Try it again after adding some context in the view, or leave it empty.

def batterycurrent(request):
    return render (request, template, {})
👤zaidfazil

Leave a comment