Done my due diligence and still having issues. Here is my goal. I'm using Django with Python to create a website with some custom coded features. The problem I'm having is this. I've tried these tutorials: http://matthewdaly.co.uk/blog/2013/12/28/django-blog-tutorial-the-next-generation-part-1/
http://ferretfarmer.net/2013/09/05/tutorial-real-time-chat-with-django-twisted-and-websockets-part-1/ (would prefer to use just django and no twisted but open to anything.
Next to last is: http://www.djangorocks.com/tutorials/how-to-create-a-basic-blog-in-django/starting-your-application.html for blogs
And finally: creating a company site with blog, news pasting, etc. Most of which I can get via models as i have done in the past.
I've made progress: But I'm stuck at this part. When I try to run python manage.py runserver i get a huge error like this:
ages\django\conf\__init__.py", line 113, in __i nit__
[shenk#LUCY2 mytest]$ python manage.py runserver
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
338, in execute_from_command_line
utility.execute()
File "c:\Python27\lib\site-packages\django\core\management\__init__.py", line
330, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "c:\Python27\lib\site-packages\django\core\management\__init__.py", line
190, in fetch_command
klass = load_command_class(app_name, subcommand)
File "c:\Python27\lib\site-packages\django\core\management\__init__.py", line
40, in load_command_class
module = import_module('%s.management.commands.%s' % (app_name, name))
File "c:\Python27\lib\importlib\__init__.py", line 37, in import_module
__import__(name)
File "c:\Python27\lib\site- packages\django\core\management\commands\runserver.py",
line 14, in <module>
from django.db.migrations.executor import MigrationExecutor
File "c:\Python27\lib\site-packages\django\db\migrations\executor.py", line 6,
in <module>
from .loader import MigrationLoader
File "c:\Python27\lib\site-packages\django\db\migrations\loader.py", line 10,
in <module>
from django.db.migrations.recorder import MigrationRecorder
File "c:\Python27\lib\site-packages\django\db\migrations\recorder.py", line 9,
in <module>
class MigrationRecorder(object):
File "c:\Python27\lib\site-packages\django\db\migrations\recorder.py", line 23
, in MigrationRecorder
class Migration(models.Model):
File "c:\Python27\lib\site-packages\django\db\migrations\recorder.py", line 24
, in Migration
app = models.CharField(max_length=255)
File "c:\Python27\lib\site-packages\django\db\models\fields\__init__.py", line
1081, in __init__
super(CharField, self).__init__(*args, **kwargs)
File "c:\Python27\lib\site-packages\django\db\models\fields\__init__.py", line
161, in __init__
self.db_tablespace = db_tablespace or settings.DEFAULT_INDEX_TABLESPACE
File "c:\Python27\lib\site-packages\django\conf\__init__.py", line 48, in __ge
tattr__
self._setup(name)
File "c:\Python27\lib\site-packages\django\conf\__init__.py", line 44, in _set
up
self._wrapped = Settings(settings_module)
File "c:\Python27\lib\site-pack
raise ImproperlyConfigured("The SECRET_KEY setting must not be empty.")
django.core.exceptions.ImproperlyConfigured: The SECRET_KEY setting must not be
empty.
Please excuse the formatting it is not cooperating 100%, working pretty good though.
Anyway I want to create a site with django and add on to it a bunch of hard coded basic modules which I can do. What I need help with as I believe I mentioned is why I cant do python manage.py runserver? Or the other question I had was the tutorials I found for blogs and such on Django were either out of date or did not work well. Please guide me towards the best way to create a company website with Django. For now I need basic skills similar to word press without and plugins (comments, blog, etc.) I can add more advanced functionality myself once this is working. The info on the Django Doc's only works like 20% of the time.
Any help would be appreciated, my preferred answer is a bit of an explanmation how to use it, as well as what could be causing my runserver issues.
Any response is much appreciated. I know this isn't the place, but send me a message on SO and perhaps we can work out payment in order to learn from you, get the base application done. After that I can write the other modules myself. (Yes, you'll be complicated and you can telecommute as I'm in PA outside Philly.
P.S. I'm an advanced C/C++ dev, a bit of C#, JS, Java, and mainly Python.
If you need any more info I can help. I'm great with python and even .NET MVC but django is a bit different so any guidance is appreciated.
Thanks in advance.
It says you've not configured the SECRET_KEY setting. You need to set the value of the SECRET_KEY variable in your_app_name/settings.py - if you used the command python manage.py startproject to create your Django project, it should have done this for you.
See here: https://docs.djangoproject.com/en/1.8/ref/settings/#secret-key
open settings.py
add
SECRET_KEY = "IWANTDJANGO4SUMREASON"
to the bottom
According to your error log, you've improperly configured your Django application. The SECRET_KEY setting must not be empty. Please check your settings.py which is loaded by manage.py and make sure the SECRET_KEY contains an appropriate value. That should get you somewhere further.
On the other hand, I would suggest reading the official documentation aswell as follow the official tutorial on how to get started. These are more often up-to-date and follow the official guidelines.
Related
My blog.models is using:
from django.contrib.auth.models import User
That model is being called from my script which I run as a task every hour. Here's the error that I'm seeing:
Traceback (most recent call last):
File "/home/redinv/src/cron.py", line 8, in <module>
from blog.models import ImagePost, MyPost, ScheduledPost
File "/home/redinv/src/blog/models.py", line 3, in <module>
from django.contrib.auth.models import User
File "/usr/lib/python3.8/site-packages/django/contrib/auth/models.py", line 2, in <module>
from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager
File "/usr/lib/python3.8/site-packages/django/contrib/auth/base_user.py", line 47, in <module>
class AbstractBaseUser(models.Model):
File "/usr/lib/python3.8/site-packages/django/db/models/base.py", line 103, in __new__
app_config = apps.get_containing_app_config(module)
File "/usr/lib/python3.8/site-packages/django/apps/registry.py", line 252, in get_containing_app_config
self.check_apps_ready()
File "/usr/lib/python3.8/site-packages/django/apps/registry.py", line 134, in check_apps_ready
settings.INSTALLED_APPS
File "/usr/lib/python3.8/site-packages/django/conf/__init__.py", line 79, in __getattr__
self._setup(name)
File "/usr/lib/python3.8/site-packages/django/conf/__init__.py", line 60, in _setup
raise ImproperlyConfigured(
django.core.exceptions.ImproperlyConfigured: Requested setting INSTALLED_APPS, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.
2020-06-25 00:50:25 -- Completed task, took 3.95 seconds, return code was 1.
In my settings file under INSTALLED_APPS =, I already have:
'django.contrib.auth',
This code is of course working locally on my machine and I'm trying to figure what's the issue here?
I tried running that script from two locations to see if there was an issue trying to find the import files:
/home/username/src
/home/username/src/blog
Same result for both.
Any assistance is appreciate it, I'm pretty new at python.
Thanks
If you want to run Django code from outside the context of a website, you need to initialize Django first. There are two ways to do that:
Run the setup function to set things up; this part of the Django docs explains how to do that
Change the code that you want to run in your task into a management command. This is a little more work, but I would recommend it as a better option in the long term.
I am trying to move a Python pyramid app that I'm writing from one server to another. I checked the code out from source control and ran a python setup.py develop to prepare the environment, but when I try to run pserve development.ini I get the following traceback:
2013-02-27 20:38:20,269 INFO [pyramid_scss][MainThread] adding asset path /home/pgrace/repos/Asterisk-WebApps/Cedar-Root/opt/cedar/cedar/assets/scss
Traceback (most recent call last):
File "/home/pgrace/venvs/pyramid/bin/pserve", line 8, in <module>
load_entry_point('pyramid==1.4', 'console_scripts', 'pserve')()
File "/home/pgrace/venvs/pyramid/lib/python2.6/site-packages/pyramid/scripts/pserve.py", line 50, in main
return command.run()
File "/home/pgrace/venvs/pyramid/lib/python2.6/site-packages/pyramid/scripts/pserve.py", line 304, in run
global_conf=vars)
File "/home/pgrace/venvs/pyramid/lib/python2.6/site-packages/pyramid/scripts/pserve.py", line 328, in loadapp
return loadapp(app_spec, name=name, relative_to=relative_to, **kw)
File "/home/pgrace/venvs/pyramid/lib/python2.6/site-packages/paste/deploy/loadwsgi.py", line 247, in loadapp
return loadobj(APP, uri, name=name, **kw)
File "/home/pgrace/venvs/pyramid/lib/python2.6/site-packages/paste/deploy/loadwsgi.py", line 272, in loadobj
return context.create()
File "/home/pgrace/venvs/pyramid/lib/python2.6/site-packages/paste/deploy/loadwsgi.py", line 710, in create
return self.object_type.invoke(self)
File "/home/pgrace/venvs/pyramid/lib/python2.6/site-packages/paste/deploy/loadwsgi.py", line 146, in invoke
return fix_call(context.object, context.global_conf, **context.local_conf)
File "/home/pgrace/venvs/pyramid/lib/python2.6/site-packages/paste/deploy/util.py", line 56, in fix_call
val = callable(*args, **kw)
File "/home/pgrace/repos/Asterisk-WebApps/Cedar-Root/opt/cedar/cedar/__init__.py", line 18, in main
config.include("pyramid_scss")
File "/home/pgrace/venvs/pyramid/lib/python2.6/site-packages/pyramid/config/__init__.py", line 773, in include
c(configurator)
File "/home/pgrace/venvs/pyramid/lib/python2.6/site-packages/pyramid_scss/__init__.py", line 88, in includeme
scss.LOAD_PATHS = ','.join([scss.LOAD_PATHS, ','.join(load_paths)])
AttributeError: 'module' object has no attribute 'LOAD_PATHS'
Now, I can tell that the problem originates in pyramid_scss, but as far as I can tell the code it references is fine, it's as if the module class does not contain the LOAD_PATHS directive. I'm trying to figure out which module it's referring to so that I can track down if I'm missing a dependency or something. Does anyone have any ideas how I'd go about identifying where the module reference is pointing to so I can check that code?
EDIT:
The error comes in the includeme definition which from what I've read is automatically included every time a pyramid-specific package is ...instantiated? Maybe? At any rate, it's saying that scss.LOAD_PATHS does not exist, yes, but there's no scss class in either pyramid_scss or pyScss packages, leading me to wonder if there's some other class that's being late-bound or something.
def includeme(config):
load_paths, static_path = _get_import_paths(config.registry.settings)
scss.LOAD_PATHS = ','.join([scss.LOAD_PATHS, ','.join(load_paths)])
scss.STATIC_ROOT = static_path
config.add_renderer('scss', renderer_factory)
The Scss class in pyScss does include a LOAD_PATHS directive but I don't see where the object scss is bound to a Scss class definition. I'm wondering whether there's something missing in the def includeme from above that might be part of the answer, but then it begs the question -- this worked right on the other machine, why break now? There's something else missing that I'm just not picking up on.
From examining the code for the scss package, it looks like the LOAD_PATHS global variable might have been moved from __init__.py to config.py.
Thus, if you want to try to fix the pyramid_scss app, you could change line 88 of pyramid_scss/__init__.py to read:
scss.config.LOAD_PATHS = ','.join([scss.config.LOAD_PATHS, ','.join(load_paths)])
The one-but-last line tells you which module is affected:
scss.LOAD_PATHS = ','.join([scss.LOAD_PATHS, ','.join(load_paths)])
AttributeError: 'module' object has no attribute 'LOAD_PATHS'
So the scss module has no LOAD_PATHS attribute.
I am trying to make an old Django project run again.
Update #1: I removed the arguments extra_thumbnails and size so the server is running. But now I don't have proper thumbnails of my pictures...
image = ImageWithThumbnailsField(
upload_to='images',
thumbnail={'size': (120, 120)},
extra_thumbnails={
'icon': {'size': (32, 32), 'options': ['crop', 'upscale']},
'large': {'size': (640, 640)},
}
now looks only:
image = ImageField(
upload_to='images')
--
After seemingly having solved issues with old sorl.thumbnail versions and deprecated expressions I now get this error when running
python manage.py runserver
I also tried to copy & paste my old files into a new Django project and get the exactly same error. Maybe someone here has a clue where the problem lies?
Unhandled exception in thread started by <bound method Command.inner_run of <django.contrib.staticfiles.management.commands.runserver.Command object at 0x2a80510>>
Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/django/core/management/commands/runserver.py", line 88, in inner_run
self.validate(display_num_errors=True)
File "/usr/lib/python2.7/dist-packages/django/core/management/base.py", line 249, in validate
num_errors = get_validation_errors(s, app)
File "/usr/lib/python2.7/dist-packages/django/core/management/validation.py", line 35, in get_validation_errors
for (app_name, error) in get_app_errors().items():
File "/usr/lib/python2.7/dist-packages/django/db/models/loading.py", line 146, in get_app_errors
self._populate()
File "/usr/lib/python2.7/dist-packages/django/db/models/loading.py", line 61, in _populate
self.load_app(app_name, True)
File "/usr/lib/python2.7/dist-packages/django/db/models/loading.py", line 78, in load_app
models = import_module('.models', app_name)
File "/usr/lib/python2.7/dist-packages/django/utils/importlib.py", line 35, in import_module
__import__(name)
File "/home/me/Documents/wdws/wdws/../wdws/cityofwindows/models.py", line 73, in <module>
class Image(models.Model):
File "/home/me/Documents/wdws/wdws/../wdws/cityofwindows/models.py", line 83, in Image
'large': {'size': (640, 640)},
File "/usr/lib/python2.7/dist-packages/django/db/models/fields/files.py", line 233, in __init__
super(FileField, self).__init__(verbose_name, name, **kwargs)
TypeError: __init__() got an unexpected keyword argument 'extra_thumbnails'
I need to re-build the project just for visual documentation locally... so also any hints on how to quickly re-run outdated django-projects are very welcome!!
Thanks a lot!
(using Ubuntu 12.04)
A guess into the dark: Remove the keyword argument extra_thumbnails in the field definition FileField in the file cityofwindows/models.py
If this does not solve the problem, please post the cityofwindows/models.py file.
You probably uses another version of Django. Install Django 1.0 (https://www.djangoproject.com/download/1.0.4/tarball/) is the easiest why, but not the best. You'd better update your project with the standards of the version 1.3 (see 1.4)
I have used the ploneformgen for creating the input form.
When I try to edit the saved data entry using the uwosk.pfg.d2c adapter in the form using the edit tab, I get the following error:
<FSControllerPythonScript at /MySite/update_version_on_edit used for /MySite/materials-requirement/material-requirement-form/requirement-for-approval/trial>
Line 11
Module Products.CMFEditions.utilities, line 109, in isObjectChanged
Module Products.CMFEditions.CopyModifyMergeRepositoryTool, line 415, in isUpToDate
Module Products.CMFEditions.ArchivistTool, line 396, in isUpToDate
Module Products.CMFEditions.ZVCStorageTool, line 308, in getModificationDate
Module Products.Archetypes.ExtensibleMetadata, line 455, in modified
Module Products.Archetypes.BaseObject, line 237, in getField
Module Products.Archetypes.BaseObject, line 821, in Schema
Module zope.component.hooks, line 104, in adapter_hook
Module archetypes.schemaextender.extender, line 146, in cachingInstanceSchemaFactory
Module archetypes.schemaextender.extender, line 186, in instanceSchemaFactory
Module plone.memoize.instance, line 51, in memogetter
Module uwosh.pfg.d2c.extender, line 217, in getFields
Module uwosh.pfg.d2c.content.dataentry, line 39, in getForm
Module uwosh.pfg.d2c.content.dataentry, line 53, in getFormAdapter
Module Products.CMFCore.utils, line 123, in getToolByName
AttributeError: uid_catalog
How do I fix this error.I require the steps as I use the GUI, or ZMI only. I use plone 4.1, ploneformgen 1.7.1 and d2c adapter 2.1.5
It looks like the product breaks in combination with CMFEditions. Try editing uwosh.pfg.d2c.content.dataentry to add an import at the top, then alter line 53 to get to the uid_catalog by a different route.
You'll need to find the file first; search for uwosh.pfg.d2c in the bin/instance script. That'll give you the location of the egg. Within the egg, locate the file uwosh/pfg/d2c/content/dataentry.py and open it in an editor.
To the top, with the other import statements, add the following line:
from zope.app.component.hooks import getSite
and alter line 54 (was line 53, but you added a line to the top); it currenntly reads:
catalog = getToolByName(self, 'uid_catalog')
where you change self to getSite() to make it read:
catalog = getToolByName(getSite(), 'uid_catalog')
Altering the egg in this manner is not portable; you'd have to do so for each and every installation of your site. If the above alteration works for you, please report it to the author of the package so it can be fixed in a new release.
There currently is an issue in the package issue tracker that seems to be related, see issue 7, where you could follow up on this. Alternatively, you could file a ticket in the new GitHub issue tracker for this package.
Yes, the package author, Nathan van Gheem, frequents Stack Overflow as well, but you should not count on him discovering the issue here. Filing an issue in the supported locations mean more people can find it and help out, too
Can anyone help me get rid of these warnings in Django please?
/usr/lib/python2.6/site-packages/simplejson-2.1.5-py2.6-linux-x86_64.egg/simplejson/_speedups.py:3: UserWarning: Module taggit was already imported from /var/www/html/matilah/taggit/__init__.py, but /usr/lib/python2.6/site-packages/django_taggit-0.9.3-py2.6.egg is being added to sys.path
Traceback (most recent call last):
File "manage.py", line 11, in <module>
execute_manager(settings)
File "/usr/lib/python2.6/site-packages/django/core/management/__init__.py", line 438, in execute_manager
utility.execute()
File "/usr/lib/python2.6/site-packages/django/core/management/__init__.py", line 379, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/lib/python2.6/site-packages/django/core/management/__init__.py", line 261, in fetch_command
klass = load_command_class(app_name, subcommand)
File "/usr/lib/python2.6/site-packages/django/core/management/__init__.py", line 67, in load_command_class
module = import_module('%s.management.commands.%s' % (app_name, name))
File "/usr/lib/python2.6/site-packages/django/utils/importlib.py", line 35, in import_module
__import__(name)
File "/usr/lib/python2.6/site-packages/haystack/__init__.py", line 154, in <module>
handle_registrations()
File "/usr/lib/python2.6/site-packages/haystack/__init__.py", line 151, in handle_registrations
search_sites_conf = importlib.import_module(settings.HAYSTACK_SITECONF)
File "/usr/lib/python2.6/site-packages/django/utils/importlib.py", line 35, in import_module
__import__(name)
File "/var/www/html/matilah/search_sites.py", line 2, in <module>
haystack.autodiscover()
File "/usr/lib/python2.6/site-packages/haystack/__init__.py", line 106, in autodiscover
app_path = importlib.import_module(app).__path__
File "/usr/lib/python2.6/site-packages/django/utils/importlib.py", line 35, in import_module
__import__(name)
File "/var/www/html/matilah/disqus/__init__.py", line 5, in <module>
from django.utils import simplejson as json
File "/usr/lib/python2.6/site-packages/django/utils/simplejson/__init__.py", line 111, in <module>
import simplejson
File "/usr/lib/python2.6/site-packages/simplejson-2.1.5-py2.6-linux-x86_64.egg/simplejson/__init__.py", line 111, in <module>
File "/usr/lib/python2.6/site-packages/simplejson-2.1.5-py2.6-linux-x86_64.egg/simplejson/decoder.py", line 7, in <module>
File "/usr/lib/python2.6/site-packages/simplejson-2.1.5-py2.6-linux-x86_64.egg/simplejson/scanner.py", line 10, in <module>
File "/usr/lib/python2.6/site-packages/simplejson-2.1.5-py2.6-linux-x86_64.egg/simplejson/scanner.py", line 6, in _import_c_make_scanner
File "/usr/lib/python2.6/site-packages/simplejson-2.1.5-py2.6-linux-x86_64.egg/simplejson/_speedups.py", line 7, in <module>
File "/usr/lib/python2.6/site-packages/simplejson-2.1.5-py2.6-linux-x86_64.egg/simplejson/_speedups.py", line 4, in __bootstrap__
File "/usr/lib/python2.6/site-packages/pkg_resources.py", line 841, in resource_filename
self, resource_name
File "/usr/lib/python2.6/site-packages/pkg_resources.py", line 1310, in get_resource_filename
self._extract_resource(manager, self._eager_to_zip(name))
File "/usr/lib/python2.6/site-packages/pkg_resources.py", line 1332, in _extract_resource
self.egg_name, self._parts(zip_path)
File "/usr/lib/python2.6/site-packages/pkg_resources.py", line 921, in get_cache_path
self.extraction_error()
File "/usr/lib/python2.6/site-packages/pkg_resources.py", line 887, in extraction_error
raise err
pkg_resources.ExtractionError: Can't extract file(s) to egg cache
The following error occurred while trying to extract file(s) to the Python egg
cache:
[Errno 13] Permission denied: '/home/interworx/.python-eggs'
The Python egg cache directory is currently set to:
/home/interworx/.python-eggs
Perhaps your account does not have write access to this directory? You can
change the cache directory by setting the PYTHON_EGG_CACHE environment
variable to point to an accessible directory.
I'm not sure if the "Module was already imported" error has to do with the "cannot extract PYTHON EGG" error.
In my WSGI I already have the following line os.environ['PYTHON_EGG_CACHE'] = rel('python-eggs') and I know for sure that works. Otherwise WSGI won't load my app. So I'm not sure what to do here.
Thanks!
When you get a message like "Perhaps your account does not have write access to this directory?" it's best to do a quick test. Try changing it to "/tmp" (which is writable by everyone) and see if things start working. If that fixes it, you can then identify a more appropriate directory and make sure that you (or the server) have write access to it.
Update: You are correct in choosing to tackle the earliest error message first. Here is a quick utility, Python Module Dump, that I wrote a few years ago for tracking down a mis-included module error. You might try inserting it at interesting points along your initialization code path and see if you can spot when the earlier import occurred.
There's a chance that your initial problem "Module was already imported" does in fact have to do with the permissions error you have going. Your best option would be to fix the permissions/ownership settings on the /home/interworx/.python-eggs directory (as stated by Peter Rowell above).
I came across this great little refresher on permissions today at the Google Code University. Wouldn't hurt to skim through this when you have some time: http://code.google.com/edu/tools101/linux/ownership_permissions.html
Just read the comments above here is my thoughts:
I think the problem is that the .wsgi file is not setting the environment variable in time. Can you please post your .wsgi file? Also, how are you grabbing the packages? Is it a script? Manually via pip?