Django import error - bad argument to internal function
Question: I'm making a basic time-card program. I'm getting an error while importing
views from urls.py. The other files in the app (models, forms, etc) can be
imported, but any call to import views returns an error I haven't seen before.

    
    
    Request Method: GET
    Request URL: http://127.0.0.1:8000/admin/
    
    Django Version: 1.5
    Python Version: 3.3.0
    Installed Applications:
    ('django.contrib.auth',
     'django.contrib.contenttypes',
     'django.contrib.sessions',
     'django.contrib.sites',
     'django.contrib.messages',
     'django.contrib.staticfiles',
     'django.contrib.admin',
     'django.contrib.admindocs',
     'timesheets')
    Installed Middleware:
    ('django.middleware.common.CommonMiddleware',
     'django.contrib.sessions.middleware.SessionMiddleware',
     'django.middleware.csrf.CsrfViewMiddleware',
     'django.contrib.auth.middleware.AuthenticationMiddleware',
     'django.contrib.messages.middleware.MessageMiddleware')
    
    
    Traceback:
    File "C:\Python33\lib\site-packages\django\core\handlers\base.py" in get_response
      103.                     resolver_match = resolver.resolve(request.path_info)
    File "C:\Python33\lib\site-packages\django\core\urlresolvers.py" in resolve
      319.             for pattern in self.url_patterns:
    File "C:\Python33\lib\site-packages\django\core\urlresolvers.py" in url_patterns
      347.         patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
    File "C:\Python33\lib\site-packages\django\core\urlresolvers.py" in urlconf_module
      342.             self._urlconf_module = import_module(self.urlconf_name)
    File "C:\Python33\lib\site-packages\django\utils\importlib.py" in import_module
      35.     __import__(name)
    File "c:\timecards\timecards\urls.py" in <module>
      10.   url(r'^/', include('timesheets.urls')),
    File "C:\Python33\lib\site-packages\django\conf\urls\__init__.py" in include
      25.         urlconf_module = import_module(urlconf_module)
    File "C:\Python33\lib\site-packages\django\utils\importlib.py" in import_module
      35.     __import__(name)
    File "c:\timecards\timesheets\urls.py" in <module>
      2. from timesheets import views
    
    Exception Type: SystemError at /admin/
    Exception Value: ..\Objects\tupleobject.c:143: bad argument to internal function
    

My timesheets.urls.py is:

    
    
    from django.conf.urls import patterns, include, url
    from timesheets import views
    # Uncomment the next two lines to enable the admin:
    from django.contrib import admin
    admin.autodiscover()
    
    urlpatterns = patterns('',
        # Examples:
        # url(r'^$', 'timecards.views.home', name='home'),
        # url(r'^timecards/', include('timecards.foo.urls')),
        url(r'^$', views.login),
        url(r'^logout/$', views.logout),
        url(r'^login/$', views.login),
        url(r'^timecards/$', views.timecards), 
        url(r'^timecards/add/$', views.addcard),
        # 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)),
    )
    

timesheets.views.py is:

    
    
    from django.shortcuts import render, redirect
    from django.contrib.auth import authenticate, login, logout
    from timesheets.forms import AppointmentForm
    from timesheets.models import Appointment
    
    def login(request):
        context={'next':'/timecards/', 'username':''}
        if request.method == 'POST':
            username = request.POST['username']
            password = request.POST['password']
            context['username'] = ''
            user = authenticate(username=username, password=password)
            if user is not None:
                if user.is_active:
                    login(request, user)
                    redirect('timecards')
            else:
                context['error'] ='Did not find match for username and password'
        render('login.html', context)
    
    def logout(request):
        logout(request)
        redirect('login')
    
    def timecards(request):
        if not request.user.is_authenticated():
            redirect('login')
        employee = request.user
        timecards = Appointment.objects.get('employee_id'=employee.id)
        context = {'employee': employee, 'timecards':timecards}
        return render(request, 'timecards.html', context)
    
    def addcard(request):
        if not request.user.is_authenticated():
            redirect('login')
        employee = request.user
        if request.method == 'POST':
            form = AppointmentForm(request.POST)
            if form.is_valid():
                cd = form.cleaned_data
                appoint = form.save(commit=False)
                appoint.employee_id = employee.id
                appoint.save()
                return redirect('timecards')
        else:
            form = AppointmentForm()
        context = {'employee': employee, 'form':form}
        return render(request,'addcards.html', context)
    


Answer: Had similar issue but problem with my app, and none of the above solution
worked. I tried running my views.py in python console and found the error in
it. after i changed it worked for me.

