I can't import markup in my django project - django

The current version of my using django is 1.6.3
i write a code
{% load markup %}
in my blog_list.html
and i got error says
'markup' is not a valid tag library: Template library markup not found, tried django.templatetags.markup,django.contrib.admin.templatetags.markup,django.contrib.staticfiles.templatetags.markup`
So i check the docs , and i found the way, then i add 'django.contrib.markup' to INSTALL_APPS settings. when i run server i got this:
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/__init__.py", line 399, in execute_from_command_line
utility.execute()
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/__init__.py", line 392, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/base.py", line 242, in run_from_argv
self.execute(*args, **options.__dict__)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/base.py", line 280, in execute
translation.activate('en-us')
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/utils/translation/__init__.py", line 130, in activate
return _trans.activate(language)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/utils/translation/trans_real.py", line 188, in activate
_active.value = translation(language)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/utils/translation/trans_real.py", line 177, in translation
default_translation = _fetch(settings.LANGUAGE_CODE)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/utils/translation/trans_real.py", line 159, in _fetch
app = import_module(appname)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/utils/importlib.py", line 40, in import_module
__import__(name)
ImportError: No module named markup
So i searched markup with macports,and i installed the py27-markupsafe. And i can't import it either. What am i suppose to do ?

If you have a look at the Django Depreciation Timeline you'll notice the following:
django.contrib.markup will be removed following an accelerated deprecation.
which means that markup is not automatically included with Django as of 1.6. You can read more about it here.
As a replacement, I have had success with django-markdown-deux which once installed provides a template tag:
{% load markdown_deux_tags %}
{{ myvar|markdown }}

Assuming you are using old Django (before this was depricated), add the following to INSTALLED_APPS in your settings.py:
'django.contrib.markup'
That should do the trick.

Related

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!

Migration urls in app ...has no Migration class

When I try to run migration I get "Migration urls in app *** has no Migration class"? I just added new app.
Have no idea what direction to look. Traceback:
C:\Users\PAPA\DEV\liberty\lib\site-packages\django\db\models\__init__.py:55:
RemovedInDjango19Warning: The utilities in django.db.models.loading are deprecated
in favor of the new application loading system.
from . import loading
Traceback (most recent call last): File "manage.py", line 22, in <module>
execute_from_command_line(sys.argv)
File "...\django\core\management\__init__.py", line 338, in execute_from_command_line
utility.execute()
File "...\django\core\management\__init__.py", line 330, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "...\django\core\management\base.py", line 390, in run_from_argv
self.execute(*args, **cmd_options)
File "...\django\core\management\base.py", line 441, in execute
output = self.handle(*args, **options)
File "...\django\core\management\commands\makemigrations.py", line 63, in handle
loader = MigrationLoader(None, ignore_no_migrations=True)
File "...\django\db\migrations\loader.py", line 47, in __init__
self.build_graph()
File "...\django\db\migrations\loader.py", line 174, in build_graph
self.load_disk()
File "...\django\db\migrations\loader.py", line 109, in load_disk
"Migration %s in app %s has no Migration class" % (migration_name, app_config.label)
django.db.migrations.loader.BadMigrationError: Migration urls in app expense has no
Migration class
That exception
BadMigrationError: "Migration *** in app *** has no Migration class"
is raised if the "migrations/" directory of the application contains a file that is not a valid migration file.
In your case it is a file "urls.py" in migrations of the application "expense".

django-seo setting up, models aren't loaded yet

I'm trying to add django-seo into my site. But I can't cope with setting up. I followed instructions documentation, but error occurs.
This is what I did:
Installed django-seo packacge
Added rollyourown.seo to INSTALED_APPS
Created seo.py file in my site content app
And this is what I wrote into seo.py file:
from rollyourown import seo
class Metadata(seo.Metadata):
title = seo.Tag(head=True, max_length=68)
description = seo.MetaTag(max_length=155)
keywords = seo.KeywordTag()
heading = seo.Tag(name="h1")
class Meta:
seo_views = ('SiteContent',)
seo_models = ('SiteContent',)
When Meta class is removed, I can't add any meta tags to contnet via Django Admin Site( I registered it in admin site ). I've read that django-seo use get_absolute_url() to deal with it. But in my site app I don't use this function for provide more some utilities to multilanguage.
But if i add Meta class, i will get this error:
Traceback (most recent call last):
File "F:/Site/manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "F:\Python27\lib\site-packages\django\core\management\__init__.py", line 385, in execute_from_command_line
utility.execute()
File "F:\Python27\lib\site-packages\django\core\management\__init__.py", line 354, in execute
django.setup()
File "F:\Python27\lib\site-packages\django\__init__.py", line 21, in setup
apps.populate(settings.INSTALLED_APPS)
File "F:\Python27\lib\site-packages\django\apps\registry.py", line 108, in populate
app_config.import_models(all_models)
File "F:\Python27\lib\site-packages\django\apps\config.py", line 202, in import_models
self.models_module = import_module(models_module_name)
File "F:\Python27\lib\importlib\__init__.py", line 37, in import_module
__import__(name)
File "F:\Python27\lib\site-packages\djangoseo-1.0-py2.7.egg\rollyourown\seo\models.py", line 10, in <module>
__import__(module_name)
File "F:\Site\SiteContent\seo.py", line 5, in <module>
class Metadata(seo.Metadata):
File "F:\Python27\lib\site-packages\djangoseo-1.0-py2.7.egg\rollyourown\seo\base.py", line 166, in __new__
options = Options(Meta, help_text)
File "F:\Python27\lib\site-packages\djangoseo-1.0-py2.7.egg\rollyourown\seo\options.py", line 19, in __init__
self._set_seo_models(meta.pop('seo_models', []))
File "F:\Python27\lib\site-packages\djangoseo-1.0-py2.7.egg\rollyourown\seo\options.py", line 96, in _set_seo_models
seo_models.extend(models.get_models(app))
File "F:\Python27\lib\site-packages\django\db\models\__init__.py", line 54, in alias
return getattr(loading, function_name)(*args, **kwargs)
File "F:\Python27\lib\site-packages\django\utils\lru_cache.py", line 101, in wrapper
result = user_function(*args, **kwds)
File "F:\Python27\lib\site-packages\django\apps\registry.py", line 168, in get_models
self.check_models_ready()
File "F:\Python27\lib\site-packages\django\apps\registry.py", line 131, in check_models_ready
raise AppRegistryNotReady("Models aren't loaded yet.")
django.core.exceptions.AppRegistryNotReady: Models aren't loaded yet.
I tried diffrent solutions but nothing helped.
Django-SEO is not compatible with Django 1.7, which is the first version of Django that includes the AppRegistry.
Either rollback to Django 1.6.x or remove Django-SEO.
I got it working by changing get_query_set() to get_queryset()(changed in django1.8) in file rollyourown\seo\backends.py
As original Django-SEO is not supported anymore, these guys made and support their own version / fork of Django-SEO. I use it with Django 1.8.8, Python 3 is supported too.
https://github.com/whyflyru/django-seo

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.

Django MongoDB problem

my django app run with mysql, but when i try with mongodb then show thie error
Traceback (most recent call last):
File "manage.py", line 14, in <module>
execute_manager(settings)
File "/home/abdullah/django-trunk/django/core/management/__init__.py", line 442, in execute_manager
utility.execute()
File "/home/abdullah/django-trunk/django/core/management/__init__.py", line 379, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/abdullah/django-trunk/django/core/management/base.py", line 191, in run_from_argv
self.execute(*args, **options.__dict__)
File "/home/abdullah/django-trunk/django/core/management/base.py", line 209, in execute
translation.activate('en-us')
File "/home/abdullah/django-trunk/django/utils/translation/__init__.py", line 106, in activate
return _trans.activate(language)
File "/home/abdullah/django-trunk/django/utils/translation/trans_real.py", line 191, in activate
_active.value = translation(language)
File "/home/abdullah/django-trunk/django/utils/translation/trans_real.py", line 180, in translation
default_translation = _fetch(settings.LANGUAGE_CODE)
File "/home/abdullah/django-trunk/django/utils/translation/trans_real.py", line 157, in _fetch
app = import_module(appname)
File "/home/abdullah/django-trunk/django/utils/importlib.py", line 35, in import_module
__import__(name)
File "/home/abdullah/django-trunk/django/contrib/admin/__init__.py", line 3, in <module>
from django.contrib.admin.helpers import ACTION_CHECKBOX_NAME
File "/home/abdullah/django-trunk/django/contrib/admin/helpers.py", line 2, in <module>
from django.contrib.admin.util import (flatten_fieldsets, lookup_field,
File "/home/abdullah/django-trunk/django/contrib/admin/util.py", line 1, in <module>
from django.db import models
File "/home/abdullah/django-trunk/django/db/__init__.py", line 27, in <module>
connection = connections[DEFAULT_DB_ALIAS]
File "/home/abdullah/django-trunk/django/db/utils.py", line 82, in __getitem__
conn = backend.DatabaseWrapper(db, alias)
File "/usr/local/lib/python2.6/dist-packages/django_mongodb_engine-0.4.0-py2.6.egg/django_mongodb_engine/base.py", line 87, in __init__
self.ops = DatabaseOperations(self)
File "/usr/local/lib/python2.6/dist-packages/djangotoolbox-0.9.2-py2.6.egg/djangotoolbox/db/base.py", line 28, in __init__
super(NonrelDatabaseOperations, self).__init__()
TypeError: __init__() takes exactly 2 arguments (1 given)
** I have installed all necessary module installed, but when i want to runserver then show this message
I managed to fix the same error by using these packages on github:
https://github.com/django-nonrel/django-nonrel
https://github.com/django-nonrel/djangotoolbox
instead of the ones recommended on Django-Mongodb's setup page. Also, make sure to use the master branch of each, so as to not run into compatibility problems. If you're using pip, you can either pip install each of the following lines separately, or put them into your version of a requirements.txt file for your project:
git+https://github.com/django-nonrel/django-nonrel#master
git+https://github.com/django-nonrel/djangotoolbox#master
git+https://github.com/django-nonrel/mongodb-engine#master
And then run
pip install -r requirements.txt