Django No Module Named URLs error

2024/10/6 14:24:48

There are many similar questions posted already, but I've already tried those solutions to no avail. I'm working through a basic Django tutorial, and here is my code:

urls.py

from django.conf.urls import patterns, include, urlfrom django.contrib import admin
admin.autodiscover()urlpatterns = patterns('',# Examples:# url(r'^$', 'tango_with_django_project.views.home', name='home'),# url(r'^tango_with_django_project/', include('tango_with_django_project.foo.urls')),# Uncomment the admin/doc line below to enable admin documentation:url(r'^admin/doc/', include('django.contrib.admindocs.urls')),# Uncomment the next line to enable the admin:url(r'^admin/', include(admin.site.urls)),url(r'^rango/', include('rango.urls')), # ADD THIS NEW TUPLE!
)

views.py

from django.http import HttpResponsedef index(request):return HttpResponse("Rango says hello world!")

From the settings.py file

ROOT_URLCONF = 'tango_with_django_project.urls'

Hope you all can help get me started

Answer

Let's say I have a Django project called FailBook, with two apps, posts and links. If I look into FailBook/urls.py, I will find something like

from django.conf.urls import patterns, include, urlfrom django.contrib import admin
admin.autodiscover()urlpatterns = patterns('',url(r'^admin/', include(admin.site.urls)),url(r'^posts/', include('posts.urls')), ## Custom url includeurl(r'^links/', include('links.urls')), ## Custom url include
)

So then, when you look into the directory structure, you will notice that there are extra two urls.py files

FailBook
|-- posts|-- models.py|-- urls.py|-- views.py|-- etc.
|-- links|-- models.py|-- urls.py|-- views.py|-- etc.# urls.py file in the posts folder
from django.conf.urls import patterns, include, url
from .views import PostListView, PostDetailViewurlpatterns = patterns('',url(r'^posts/', PostListView.as_view()), url(r'^posts/(?P<post_id>\d+)', PostDetailView.as_view()),
)
# where both views are class based views, hence the as_view function call
https://en.xdnf.cn/q/70359.html

Related Q&A

Matplotlib artist to stay same size when zoomed in but ALSO move with panning?

This is a very direct follow-up on this question.Using matplotlib, Id like to be able to place a sort of "highlighting bar" over a range of data markers that I know will all be in a straight …

How to invoke Lambda function with Event Invocation Type via API Gateway?

Docs says:By default, the Invoke API assumes RequestResponse invocation type. You can optionally request asynchronous execution by specifying Event as the InvocationType. So all I can send to my functi…

How do I unlock the app engine database when localhost runs?

Right now I get a blank page when localhost runs, but the deployed app is fine. The logs show the "database is locked". How do I "unlock" the database for localhost?

PyCrypto: Generate RSA key protected with DES3 password

I have been able to create a RSA key protected by password with DES3 (well... I think because Im very new to this encryption world) by using the command:openssl genrsa -out "/tmp/myKey.pem" -…

Normalize/Standardize a numpy recarray

I wonder what the best way of normalizing/standardizing a numpy recarray is. To make it clear, Im not talking about a mathematical matrix, but a record array that also has e.g. textual columns (such as…

How to read /dev/log?

I would like to directly access to syslog messages from Python by reading /dev/log.My (very limited) understanding is that the correct way is to read from there is to bind a datagram socket. import soc…

Determining if a number evenly divides by 25, Python

Im trying to check if each number in a list is evenly divisible by 25 using Python. Im not sure what is the right process. I want to do something like this:n = [100, 101, 102, 125, 355, 275, 435, 134, …

OpenCV SimpleBlobDetector detect() call throws cv2.error: Unknown C++ exception from OpenCV code?

I need to detect semicircles on image and I find follow stuff for this: import cv2 import numpy as npdef get_circle(img_path):im = cv2.imread(img_path, cv2.IMREAD_GRAYSCALE)detector = cv2.SimpleBlobDet…

Is it possible to add a global argument for all subcommands in Click based interfaces?

I am using Click under a virtualenv and use the entry_point directive in setuptools to map the root to a function called dispatch.My tool exposes two subcommands serve and config, I am using an option …

Error importing h5py

Ive been trying to import h5py to read this type of file.Here is my code:import h5pyfile_1 = h5py.File("Out_fragment.h5py")print file_1The output is:Traceback (most recent call last):File &qu…