0
votes

I use Django-Registration-Redux in my Django project.

In settings.py, the code:

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',

In urls.py, the code:

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}),)

Then pyCharm show that my urls.py has errors: Unresolve reference 'registration'

I have run 'python manage.py migrate'. But the error still exists. Why does this happend? How can I fix it? And it's really strange that although pyCharm show error, my code run well.

PS: I write this code as the same as the django tutorial http://www.tangowithdjango.com/book17/chapters/login_redux.html

1
You should post your urls.py. The code you've posted appears to be from views.py. - Daniel Roseman
@DanielRoseman I have post both views.py and url.py. The second code is a part of urls.py which involve this problem. Please look it. - Pavel
Strange place to put it, but whatever. But why have you only posted part of urls.py? The error doesn't seem to be in that part. Post the whole thing. - Daniel Roseman
@DanielRoseman Sorry, I have update it. And I found I can run my code wll although pyCharm show that error. It's strange. - Pavel
Reload the Interpreter Path so that PyCharm can pick up and new packages you have installed. I think you may need to that every time you update your virtualenv with new packages. - Mick T

1 Answers

1
votes

This is because PyCharm does not have the same sys.path as your django project.

To get rid of the false warning, mark your top-level django directory (the one that contains manage.py) as a directory that contain sources:

  1. select the directory in pycharm, then right click
  2. in the context menu, select Mark Directory As > Sources Root