0

I am new to the environment of django and I am trying to create an url link; however, the error reads

ImportError: No module named 'myprofile'

Therefore I am stuck here asking the question of how to fix this problem. I have looked over several forum; however, I couldn't come across the solution to this particular problem. Thank You for helping.

from django.conf.urls import url
from django.conf.urls import include
from . import views

urlpatterns = [
    url(r'^$', views.index),
    url(r'^myprofile$',include("myprofile.urls"), name = myprofile)
]

2 Answers2

0

Assuming that you have an app called myprofile which includes a views.py you should form your URL like the following:

from django.conf.urls import url
from django.conf.urls import include
from myprofile import views as myprofileViews

urlpatterns = [
    url(r'^$', views.index),
    url(r'^myprofile$', myprofileViews.SomeViewName)
]

You should then have to have the following code in myprofile/views.py:

def SomeViewName(request):
   return render(request, 'index.html', context)
Rafael
  • 7,002
  • 5
  • 43
  • 52
0

Might be that you're missing __init__.py in the myprofile app. This is a file in the directory of the app, and it's enough if it's empty. This file will make python recognize the directory as a module.

Also see this question: Python error "ImportError: No module named"

Community
  • 1
  • 1
DA--
  • 723
  • 1
  • 8
  • 20