我在Django项目中使用Django-Registration-Redux。
在settings.py中,代码为:
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'rango',
#'django.contrib.sites',
'registration',
在urls.py中,代码为:
from django.conf.urls import patterns, include, url
from django.contrib import admin
from django.conf.urls.static import static
from django.conf import settings
from registration.backends.simple.views import RegistrationView
# Create a new class that redirects the user to the index page, if successful at logging
class MyRegistrationView(RegistrationView):
def get_success_url(self,request, user):
return '/rango/'
urlpatterns = patterns('',
url(r'^admin/', include(admin.site.urls)),
url(r'^rango/', include('rango.urls')),
#Add in this url pattern to override the default pattern in accounts.
url(r'^accounts/register/$', MyRegistrationView.as_view(), name='registration_register'),
(r'^accounts/', include('registration.backends.simple.urls')),)
if not settings.DEBUG:
urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
if settings.DEBUG:
urlpatterns += patterns(
'django.views.static',
(r'^media/(?P<path>.*)',
'serve',
{'document_root': settings.MEDIA_ROOT}),)
然后pyCharm显示我的urls.py有错误: 解析参考'注册'
我已经运行'python manage.py migrate'。但错误仍然存在。 为什么会这样?我该如何解决?而且奇怪的是,尽管pyCharm显示错误,但我的代码运行良好。
PS:我编写的代码与django教程http://www.tangowithdjango.com/book17/chapters/login_redux.html
相同答案 0 :(得分:1)
这是因为PyCharm与django项目没有相同的sys.path。
要清除错误警告,请将您的顶级django目录(包含 manage.py 的目录)标记为包含来源的目录: