50๐
โ
I have found the answer to my question. It was indeed an import error. For Django 1.10, you now have to import the appโs view.py, and then pass the second argument of url() without quotes. Here is my code now in urls.py:
from django.conf.urls import url
from django.contrib import admin
import main.views
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^$', main.views.home)
]
I did not change anything in the app or view.py files.
Props to @Rik Poggi for illustrating how to import in his answer to this question:
Django โ Import views from separate apps
๐คAMadinger
8๐
You should be able to use the following:
from django.conf.urls import url
from django.contrib import admin
from main import views
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^$', views.home)
]
Iโm not absolutely certain what your directory structure looks like, but using a relative import such as from . import X
is for when the files are in the same folder as each other.
๐คJoey Wilhelm
- [Django]-Django: dependencies reference nonexistent parent node
- [Django]-What is the Simplest Possible Payment Gateway to Implement? (using Django)
- [Django]-Adding attributes into Django Model's Meta class
3๐
You can use your functions by importing all of them to list and added each one of them to urlpatterns.
from django.conf.urls import url
from django.contrib import admin
from main.views import(
home,
function2,
function3,
)
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^home/$', home),
url(r'function2/^$', function2),
url(r'^$', function3),
]
๐คHarun ERGUL
- [Django]-How to print BASE_DIR from settings.py from django app in terminal?
- [Django]-Alternate Row Coloring in Django Template with More Than One Set of Rows
- [Django]-AccessDenied when calling the CreateMultipartUpload operation in Django using django-storages and boto3
Source:stackexchange.com