问题:

尝试连接到mysql的数据库时我面临的问题。 我还提供了我使用过的数据库设置。

 Traceback (most recent call last):
 File "manage.py", line 10, in <module>
 execute_from_command_line(sys.argv)
 File "/home/ar/Desktop/test/testprac/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 453, in execute_from_command_line
utility.execute()
File "/home/ar/Desktop/test/testprac/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 392, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/ar/Desktop/test/testprac/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 272, in fetch_command
klass = load_command_class(app_name, subcommand)
File "/home/ar/Desktop/test/testprac/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 77, in load_command_class
module = import_module('%s.management.commands.%s' % (app_name, name))
File "/home/arundhati/Desktop/test/testprac/local/lib/python2.7/site-packages/django/utils/importlib.py", line 35, in import_module
__import__(name)
File "/home/ar/Desktop/test/testprac/local/lib/python2.7/site-packages/django/core/management/commands/syncdb.py", line 8, in <module>
from django.core.management.sql import custom_sql_for_model, emit_post_sync_signal
File "/home/ar/Desktop/test/testprac/local/lib/python2.7/site-packages/django/core/management/sql.py", line 9, in <module>
from django.db import models
File "/home/ar/Desktop/test/testprac/local/lib/python2.7/site-packages/django/db/__init__.py", line 40, in <module>
backend = load_backend(connection.settings_dict['ENGINE'])
File "/home/ar/Desktop/test/testprac/local/lib/python2.7/site-packages/django/db/__init__.py", line 34, in __getattr__
return getattr(connections[DEFAULT_DB_ALIAS], item)
File "/home/ar/Desktop/test/testprac/local/lib/python2.7/site-packages/django/db/utils.py", line 93, in __getitem__
backend = load_backend(db['ENGINE'])
File "/home/ar/Desktop/test/testprac/local/lib/python2.7/site-packages/django/db/utils.py", line 27, in load_backend
return import_module('.base', backend_name)
File "/home/ar/Desktop/test/testprac/local/lib/python2.7/site-packages/django/utils/importlib.py", line 35, in import_module
__import__(name)
File "/home/ar/Desktop/test/testprac/local/lib/python2.7/site-packages/django/db/backends/mysql/base.py", line 17, in <module>
raise ImproperlyConfigured("Error loading MySQLdb module: %s" % e)
django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: No module named MySQLdb

数据库设置::

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
        'NAME': 'ar_test_db',                      # Or path to database file if using 
        # The following settings are not used with sqlite3:
        'USER': '',
        'PASSWORD': '',
        'HOST': '',                      # Empty for localhost through domain sockets or   '127.0.0.1' for localhost through TCP.
        'PORT': '',                      # Set to empty string for default.
    }
}

非常感谢您的帮助 !!

The problem Im facing while trying to connect to database for mysql.I have also given the database settings that i have used.Databse Settings::Thanks a lot for the help !!

问题:

遵循这个Django by example tutotrial: http ://lightbird.net/dbe/todo_list.html

教程说:

“这改变了我们的表格布局,我们必须要求Django重置并重新创建表格:

manage.py reset todo; manage.py syncdb manage.py reset todo; manage.py syncdb

但是,当我运行manage.py reset todo ,我收到错误:

$ python manage.py reset todo                                       
- Unknown command: 'reset'

这是因为我使用的是sqlite3而不是postgresql吗?

有人能告诉我重置数据库的命令是什么吗?

命令: python manage.py sqlclear todo返回错误:

$ python manage.py sqlclear todo    
CommandError: App with label todo could not be found.    
Are you sure your INSTALLED_APPS setting is correct?

所以我在settings.py中将’todo’添加到我的INSTALLED_APPS中,并再次运行python manage.py sqlclear todo ,导致此错误:

$ python manage.py sqlclear todo                                      
- NameError: name 'admin' is not defined

Following this Django by Example tutotrial here: http://lightbird.net/dbe/todo_list.htmlThe tutorial says:”This changes our table layout and we’ll have to ask Django to reset and recreate tables:manage.py reset todo; manage.py syncdb “though, when I run manage.py reset todo , I get the error:Is this because I am using sqlite3 and not postgresql?Can somebody tell me what the command is to reset the database?The command: python manage.py sqlclear todo returns the error:So I added ‘todo’ to my INSTALLED_APPS in settings.py, and ran python manage.py sqlclear todo again, resulting in this error:

问题:

按照此处找到的教程,我无法创建自定义500或404错误页面。 如果我输入了错误的网址,该页面会为我提供默认的错误页面。 有什么我应该检查,以防止自定义页面显示?

文件目录:

mysite/
    mysite/
        __init__.py
        __init__.pyc
        settings.py
        settings.pyc
        urls.py
        urls.pyc
        wsgi.py
        wsgi.pyc
    polls/
        templates/
            admin/
                base_site.html
            404.html
            500.html
            polls/
                detail.html
                index.html
        __init__.py
        __init__.pyc
        admin.py
        admin.pyc
        models.py
        models.pyc
        tests.py
        urls.py
        urls.pyc
        view.py
        views.pyc
    templates/
    manage.py

在mysite / settings.py中我启用了这些:

DEBUG = False
TEMPLATE_DEBUG = DEBUG

#....

TEMPLATE_DIRS = (
    'C:/Users/Me/Django/mysite/templates', 
)

在mysite / polls / urls.py中:

from django.conf.urls import patterns, url

from polls import views

urlpatterns = patterns('',
    url(r'^$', views.index, name='index'),
    url(r'^(?P<poll_id>\d+)/$', views.detail, name='detail'),
    url(r'^(?P<poll_id>\d+)/results/$', views.results, name='results'),
    url(r'^(?P<poll_id>\d+)/vote/$', views.vote, name='vote'),
)

我可以发布任何其他必要的代码,但是如果我使用错误的网址,我应该如何更改以获取自定义500错误页面?

编辑

解决方案:我有一个额外的

TEMPLATE_DIRS

在我的settings.py中,这导致了问题

Following the tutorial found here exactly, I cannot create a custom 500 or 404 error page.If I do type in a bad url, the page gives me the default error page.Is there anything I should be checking for that would prevent a custom page from showing up?File directories:within mysite/settings.py I have these enabled:within mysite/polls/urls.py:I can post any other code necessary, but what should I be changing to get a custom 500 error page if I use a bad url?EditSOLUTION: I had an additionalwithin my settings.py and that was causing the problem

问题:

我正在尝试使用django.contrib.auth.login将用户的ID存储在会话中。 但它没有按预期工作。

我收到错误login()只需要1个参数(给定2个)

使用login(用户)我在/ login / User获取AttributeError对象没有属性’method’

我正在使用稍微修改过的示例表单http://docs.djangoproject.com/en/dev/topics/auth/ :

from django.shortcuts import render_to_response
from django.contrib.auth import authenticate, login

def login(request):
    msg = []
    if request.method == 'POST':
        username = request.POST['u']
        password = request.POST['p']
        user = authenticate(username=username, password=password)
        if user is not None:
            if user.is_active:
                login(request, user)
                msg.append("login successful")
            else:
                msg.append("disabled account")
        else:
            msg.append("invalid login")
    return render_to_response('login.html', {'errors': msg})

login.html没有什么特别之处:

<html>
<head>
    <title></title>
</head>
<body>
    <form action="/login/" method="post">
        Login:&nbsp; <input type="text" name="u">
    <br/>
        Password:&nbsp; <input type="password" name="p">
        <input type="submit" value="Login">
    </form>
    {% if errors %}
        <ul>
            {% for error in errors %}
            <li>{{ error }}</li>
            {% endfor %}
        </ul>
    {% endif %}

</body>
</html>

有没有人知道如何使login()工作。

I’m trying to store the user’s ID in the session using django.contrib.auth.login .But it is not working not as expected.I’m getting error login() takes exactly 1 argument (2 given)With login(user) I’m getting AttributeError at /login/ User’ object has no attribute ‘method’I’m using slightly modifyed example form http://docs.djangoproject.com/en/dev/topics/auth/ :there’s nothing special about login.html:Does anybody have idea how to make login() work.

问题:

我正在尝试运行使用Django 1.6的statsd / graphite。

访问石墨URL时,出现Django模块错误

django.conf.urls.defaults中的文件“ /opt/graphite/webapp/graphite/urls.py”,第15行,导入* ImportError:没有名为默认值的模块

但是,我在/Library/Python/2.7/site-packages/django/conf/urls/找不到默认的 django包

请帮助解决此问题。

I am trying to run statsd/graphite which uses django 1.6.While accessing graphite URL, I get django module errorFile “/opt/graphite/webapp/graphite/urls.py”, line 15, in from django.conf.urls.defaults import * ImportError: No module named defaultsHowever, I do not find defaults django package inside /Library/Python/2.7/site-packages/django/conf/urls/Please help fixing this issue.