Django setup with sqlite3? - django

I am trying to follow the walkthrough on the django website and I downloaded sqlite and saved it in C:\Windows\System32 folder. When I edit the settings.py file what do I put for the Name field? Do I have to set up a database? The django literature say's that the API should take care of that for sqlite. When I run python manage.py syncdb I just get a bunch of errors. What am I doing wrong?
Jason & Casey#SUPERBEAST ~/Desktop/mysite
$ python manage.py syncdb
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "c:\Python27\lib\site-packages\django\core\management\__init__.py", line
443, in execute_from_command_line
utility.execute()
File "c:\Python27\lib\site-packages\django\core\management\__init__.py", line
382, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "c:\Python27\lib\site-packages\django\core\management\__init__.py", line
252, in fetch_command
app_name = get_commands()[subcommand]
File "c:\Python27\lib\site-packages\django\core\management\__init__.py", line
101, in get_commands
apps = settings.INSTALLED_APPS
File "c:\Python27\lib\site-packages\django\utils\functional.py", line 184, in
inner
self._setup()
File "c:\Python27\lib\site-packages\django\conf\__init__.py", line 42, in _set
up
self._wrapped = Settings(settings_module)
File "c:\Python27\lib\site-packages\django\conf\__init__.py", line 93, in __in
it__
mod = importlib.import_module(self.SETTINGS_MODULE)
File "c:\Python27\lib\site-packages\django\utils\importlib.py", line 35, in im
port_module
__import__(name)
File "c:\Users\Jason & Casey\Desktop\mysite\mysite\settings.py", line 21
}
^
SyntaxError: invalid syntax

I haven't tried django under windows but python 2.7 surely comes with sqlite out of the box.
How to setup the database?
on the top of the file:
import os
then:
PROJECT_DIR = os.path.abspath(os.path.dirname(__file__))
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(PROJECT_DIR, 'yourdatabasename.db'),
}
}
and finally a syncdb should do the trick.
If it doesn't work, mind to paste the traceback?

The problem is:
File "c:\Users\Jason & Casey\Desktop\mysite\mysite\settings.py", line 21
}
^
SyntaxError: invalid syntax
Check the syntax a paren or brace hasn't been closed properly around DATABASES.

Related

Import by fileName is not supportted

I have a django project and a dump.json file in which all the database dump is present.
I am trying to run this command to load data into my django project
django-admin loaddata dumpdata.json --settings=~/Workspace/odx-lm/lm/settings/local.py
On running the above command from the folder ~/Workspace/odx-lm/,
I am getting the following error:
Traceback (most recent call last): File
"/home/delhivery/Workspace/odx-lm/odx-lm-env/bin/django-admin.py",
line 5, in
management.execute_from_command_line() File "/home/delhivery/Workspace/odx-lm/odx-lm-env/local/lib/python2.7/site-packages/django/core/management/init.py",
line 367, in execute_from_command_line
utility.execute() File "/home/delhivery/Workspace/odx-lm/odx-lm-env/local/lib/python2.7/site-packages/django/core/management/init.py",
line 316, in execute
settings.INSTALLED_APPS File "/home/delhivery/Workspace/odx-lm/odx-lm-env/local/lib/python2.7/site-packages/django/conf/init.py",
line 53, in getattr
self._setup(name) File "/home/delhivery/Workspace/odx-lm/odx-lm-env/local/lib/python2.7/site-packages/django/conf/init.py",
line 41, in _setup
self._wrapped = Settings(settings_module) File "/home/delhivery/Workspace/odx-lm/odx-lm-env/local/lib/python2.7/site-packages/django/conf/init.py",
line 97, in init
mod = importlib.import_module(self.SETTINGS_MODULE) File "/usr/lib/python2.7/importlib/init.py", line 37, in import_module
import(name) ImportError: Import by filename is not supported.
Any help would be highly appreciated.
The value for settings must be a Python module path, not a file path.
... --settings=lm.settings.local

Django CMS 3.5.2 Internalization - translate template text

I have a couple of questions about Django CMS 3.5.2 translation.
1) My website is in three languages. I want to translate my template text into all three languages. I have tried using the {% trans 'my text' %} tag, but, when I write the python manage.py makemessages -l all command, my terminal indicates the following error message instead of creating a .po file:
RuntimeWarning,
Traceback (most recent call last):
File "manage.py", line 7, in <module>
startup.manage(path=os.path.dirname(os.path.abspath(__file__)))
File "/usr/local/lib/python2.7/site-packages/aldryn_django/startup.py", line 12, in manage
utility.execute()
File "/usr/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 "/usr/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 261, in fetch_command
commands = get_commands()
File "/usr/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 107, in get_commands
apps = settings.INSTALLED_APPS
File "/usr/local/lib/python2.7/site-packages/django/conf/__init__.py", line 54, in __getattr__
self._setup(name)
File "/usr/local/lib/python2.7/site-packages/django/conf/__init__.py", line 49, in _setup
self._wrapped = Settings(settings_module)
File "/usr/local/lib/python2.7/site-packages/django/conf/__init__.py", line 132, in __init__
% (self.SETTINGS_MODULE, e)
ImportError: Could not import settings 'settings' (Is it on sys.path? Is there an import error in the settings file?): No module named deconstruct
I am just wondering if there's another way to translate texts in Django CMS.
2) Is there a way to add the option to translate texts for non-developers?
Something like the following (but not only for page names):
Thank you!

django-admin --version error

I was working on a Django project and I ran to the error below please help.
I tried to check my django version with the " django-admin --version " command and i ran into this error below.
Traceback (most recent call last):
File "/usr/local/bin/django-admin", line 11, in <module>
sys.exit(execute_from_command_line())
File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 354, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 328, in execute
django.setup()
File "/usr/local/lib/python2.7/dist-packages/django/__init__.py", line 18, in setup
apps.populate(settings.INSTALLED_APPS)
File "/usr/local/lib/python2.7/dist-packages/django/apps/registry.py", line 85, in populate
app_config = AppConfig.create(entry)
File "/usr/local/lib/python2.7/dist-packages/django/apps/config.py", line 86, in create
module = import_module(entry)
File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
ImportError: No module named south
You have include south in your INSTALLED_APPS settings, but it is not installed.
From the traceback, it looks as if you are using Django 1.7 or later, so South is no longer required. You should remove it from INSTALLED_APPS in your settings.

How to use ArrayField in Django using PostgreSQL DB?

I want to do this import in my django models.py:
from django.contrib.postgres.fields import ArrayField
I read this documentation https://docs.djangoproject.com/en/dev/ref/contrib/ and I added
'django.contrib.postgres' into my INSTALLED_APPS in settings.py, but when I try to sync my db or to runserver I got "ImportError: No module named postgres"
Is there something else I should do or install? django.contrib.postgres is part of the core distribution right?
This is traceback:
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "c:\Python27\lib\site-packages\django\core\management\__init__.py", line 399, in execute_from_com
utility.execute()
File "c:\Python27\lib\site-packages\django\core\management\__init__.py", line 392, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "c:\Python27\lib\site-packages\django\core\management\base.py", line 242, in run_from_argv
self.execute(*args, **options.__dict__)
File "c:\Python27\lib\site-packages\django\core\management\base.py", line 280, in execute
translation.activate('en-us')
File "c:\Python27\lib\site-packages\django\utils\translation\__init__.py", line 130, in activate
return _trans.activate(language)
File "c:\Python27\lib\site-packages\django\utils\translation\trans_real.py", line 188, in activate
_active.value = translation(language)
File "c:\Python27\lib\site-packages\django\utils\translation\trans_real.py", line 177, in translation
default_translation = _fetch(settings.LANGUAGE_CODE)
File "c:\Python27\lib\site-packages\django\utils\translation\trans_real.py", line 159, in _fetch
app = import_module(appname)
File "c:\Python27\lib\site-packages\django\utils\importlib.py", line 40, in import_module
__import__(name)
ImportError: No module named postgres
django.contrib.postgres will be a part of 1.8 release.
Fortunately there are several unofficial implementations postgresql arrays in django. One of the most notable being djorm-pgarray. Another option is django-dbarray when Django 1.8 eventually gets rolled out, migration shouldn't be too difficult.

django1.4.0:ImportError: No module named base

Now I have a problem as the title. Here is my environment:
OS:ubuntu 10.10
Python:2.6.6
Django:1.4 pre-alpha
Before, I installed Django 1.1.1 for the The Django Book. Today , I removed Django 1.1.1 by cmd: sudo apt-get install --purge python-django, then get the latest version of 1.4 pre-alpha.
when I followed the tutorial on the docs.djangoproject.com, and execute cmd: python manage.py shell, it comes some error and the infomation like this:
Traceback (most recent call last):
File "manage.py", line 9, in <module>
execute_from_command_line(sys.argv)
File "/usr/local/lib/python2.6/dist-packages/django/core/management/__init__.py", line 422, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python2.6/dist-packages/django/core/management/__init__.py", line 361, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/local/lib/python2.6/dist-packages/django/core/management/base.py", line 191, in run_from_argv
self.execute(*args, **options.__dict__)
File "/usr/local/lib/python2.6/dist-packages/django/core/management/base.py", line 222, in execute
output = self.handle(*args, **options)
File "/usr/local/lib/python2.6/dist-packages/django/core/management/base.py", line 355, in handle
return self.handle_noargs(**options)
File "/usr/local/lib/python2.6/dist-packages/django/core/management/commands/shell.py", line 46, in handle_noargs
from django.db.models.loading import get_models
File "/usr/local/lib/python2.6/dist-packages/django/db/__init__.py", line 27, in <module>
connection = connections[DEFAULT_DB_ALIAS]
File "/usr/local/lib/python2.6/dist-packages/django/db/utils.py", line 81, in __getitem__
backend = load_backend(db['ENGINE'])
File "/usr/local/lib/python2.6/dist-packages/django/db/utils.py", line 23, in load_backend
return import_module('.base', backend_name)
File "/usr/local/lib/python2.6/dist-packages/django/utils/importlib.py", line 35, in import_module
__import__(name)
ImportError: No module named base
Could some guys tell me how solve this problem?
Thanks!!
The problem is probably because You have no full path for your DB backend. You probably have:
'ENGINE': 'sqlite3',
instead of:
'ENGINE': 'django.db.backends.sqlite3',
You must call manage.py from the folder where settings.py is located: ../manage.py shell
(In case using sqlite3)
(And djando 1.4)