I'm trying to add WebSolr support to my django powered app on Heroku. They have detailed instructions for an implementation using Ruby:
https://devcenter.heroku.com/articles/websolr
But I can't figure out how to tie it up to Haystack. Has any one done this?
Thanks.
Edit:
I was able to implement by modifying my settings.py file as:
HAYSTACK_URL = os.environ.get('WEBSOLR_URL', '')
HAYSTACK_CONNECTIONS = {
'default': {
'ENGINE': 'haystack.backends.solr_backend.SolrEngine',
'URL': HAYSTACK_URL,
},
}
Then running:
heroku run myproject/manage.py build_solr_schema > schema.xml
And uploading the contents of schema.xml to the advanced tab of the websolr interface. And once I ran
heroku run myproject/manage.py rebuild_index
the index was built.
I've updated the Heroku Websolr Docs to include a section on Django, based on your question. Thanks for that. For suggestions on our docs, drop a comment on this gist.
Related
I wrote a project in django framework and I use the local DataBase SQLite, and I now want to upload it to the cloud so other people who work with me can access DataBase i.e. when I create a user then that user will exist with my co-workers.
Maybe someone has a guide on how to do this without modifying the DataBase so that I do not have to modify the rest of the code?
Ok i found the answer,
what you should do is Connect Django and MongoDB Using Djongo
you can read from here
I RECOMMEND TO FOLLOW MY SETPS.
go to monogodb site -> clickHere and create free account.
create new cluster
then you will reverse to this page if no in the left side press DataBase under DEPLOYMENT and then you get.
press on Connect buttom
choose "Connect your application" and then choose python and the last version
after all this you will have this link:
for example!!!
mongodb+srv://<username>:<password>#<atlas cluster>/<myFirstDatabase>?retryWrites=true&w=majority
copy this link and do the next setps:
go back to your terminal and install this package: pip install djongo
and open settings.py
change your DATEBASE to like this:
DATABASES = {
'default': {
'ENGINE': 'djongo',
'NAME': 'your-db-name',
'CLIENT': {
'host': 'mongodb+srv://<username>:<password>#<atlascluster>/<myFirstDatabase>?retryWrites=true&w=majority'
}
}
}
in 'host' paste the link you copy from monogodb site.
in 'NAME' write your name of the database.
Now that we have the Django project (and app), you can create the collections in MongoDB using the commands:
python manage.py makemigrations <app-name>
python manage.py migrate
if you get error like 'django.db.utils.databaseerror'
what you should to do is:
It deletes all the files that are in the migrations folder that are in the apps you have created and after that run again the command above.
i am trying to deploy my site using heroku. Being a starter just following the steps given on a website. In settings my csv and database default is not getting recognised.
ALLOWED_HOSTS = config('ALLOWED_HOSTS', cast=Csv())
DATABASES = {
'default': dj_database_url.config(
default=config('DATABASE_URL')
)
}
This has nothing to do with Heroku; this wouldn't work locally either. The error message tells you all you need to know: you have not defined Csv. It's not clear what it is supposed to be, but you either need to import that function, or define it yourself.
Install python-decouple pip install python-decouple
ran into the same ordeal.
Postgis extension is installed:
:DATABASE=> SELECT postgis_version();
postgis_version
2.2 USE_GEOS=1 USE_PROJ=1 USE_STATS=1
I have the following buildpacks:
https://github.com/cyberdelia/heroku-geo-buildpack.git
https://github.com/heroku/heroku-buildpack-python.git
When I run manage.py migrate I get:
AttributeError: 'DatabaseOperations' object has no attribute 'geo_db_type'
I am using the hobby deb postgres which now supports postgis
https://devcenter.heroku.com/changelog-items/792
Do I need to install a different build pack or add some additional configuration? Everything works locally using postgis.
I finally had some time to go back and look at this. It turns out the issue was Heroku was not importing my settings correctly. I was using cookiecutter-django settings scheme that imports common settings into production and for some reason Heroku was not working as expected.
My common settings contained:
DATABASES['default']['ATOMIC_REQUESTS'] = True
DATABASES['default']['ENGINE'] = "django.contrib.gis.db.backends.postgis"
And my production contained:
DATABASES['default'] = env.db("DATABASE_URL")
Heroku did not import those common settings. When I checked in the django shell in heroku the production settings had
'ENGINE': 'django.db.backends.postgresql_psycopg2', 'ATOMIC_REQUESTS': False
After adding DATABASES['default']['ENGINE'] = "django.contrib.gis.db.backends.postgis" to production settings everything is working.
Does anybody know what could be going wrong with importing settings correctly from common.py? It seems to import the rest of the settings correctly, just not the database ones.
I'm a newbie in django so as python
I just succesfully configured my first django site over an apache server, then I configured it to work with mysql database editing the settings.py file and running the following command
python manage.py syncdb
I started playing a bit with the admin but occasionally when making get or post requests I get the following message OperationalError at "/some/route" unable to open database file
If I refresh the page loads fine, but if i keep refreshing any page in the admin the error shows up, so it's a random thing.
For what I've searched this is an issue related with sqlite, but I'm using mysql.
My database config in settings.py is the following:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'simulation',
'USER': 'root',
'PASSWORD': 'root',
'HOST': ''
}
}
I tried to specify hosts "localhost" and "127.0.0.1" but the result was the same.
It's really important for me find a solution that uses mysql as database engine.
Any help would be really appreciated! Thanks.
I've encountered a similar problem that you have right here, in my instance it seemed like my settings.py file was cached on the server. Once I deleted the .pyc files it started working fine.
Also, what happens if you change your database to sqlite? It might be worth checking that your mysql database isn't playing up instead of django.
I ran into the same problem with Django/Mysql/WSGI/Apache setup. Similar to Serakiel, I think that the problem stemmed from server caching. Restarting apache fixed the problem for me.
I was looking through http://lincolnloop.com/blog/2009/sep/15/using-django-inside-tornado-web-server/ and I thought it was interesting and useful to use parts of Django if we need it in Tornado.
Based on the setup in http://lincolnloop.com/blog/2009/sep/15/using-django-inside-tornado-web-server/ how can we use manage.py syncdb ?
Here's what i have tried so far:
I've tried shifting manage.py to the same folder as the tornado project, and ran manage.py syncdb but it returns saying that settings.py is not found.
than i tried to move setting.py to the same folder and ran manage.py again. It tells me that no fixtures found. This time round, I have no idea how to configure settings.py since this is not a Django project.
Any advice or thoughts?
=================updates======================
Hi all,
continuing from the above an using advice provided by Agos,
i've tried running python manage.py syncdb --settings=dj_tornado and it returns
`"Error: Can't find the file 'settings.py'` in the directory containing 'manage.py'`. It appears you've customized things.
You'll have to run django-admin.py, passing it your settings module.
(If the file settings.py does indeed exist, it's causing an ImportError somehow.)"
So what i did is to run django-admin.py syncdb --settings=dj_tornado and it returns "django.core.exceptions.ImproperlyConfigured: You haven't set the database ENGINE setting yet."
But the weird thing is that the database engine has been set. How would I go about fixing this? i'm using django 1.2.3 and Tornado 0.2 by the way.
=================updates again======================
Hi all,
i've applied the advice provided by Agos, with a settings.py file in teh same folder as manage.py, and ran the command django-admin.py syncdb --settings=dj_tornado.
I still received the error:
django.core.exceptions.ImproperlyConfigured: You haven't set the database ENGINE setting yet.
But i have already configured the database based engine as follows:
in dj_tornado.py:
from django.conf import settings
settings.configure(
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': 'dev.db',
}
}
)
I'm kind of at my wits end. How do i use syncdb outside of Django project?
Best.
If I got it correctly, you can just use the --settings switch to point manage.py to the dj_tornado.py, which is your settings file after all
Update 1
from the help, available at python manage.py help:
Options:
--settings=SETTINGS The Python path to a settings module, e.g.
"myproject.settings.main". If this isn't provided, the
DJANGO_SETTINGS_MODULE environment variable will be
used.
So I would try this:
python manage.py syncdb --settings=dj_tornado
Update 2
Another error, another update to the answer!
First of all, consider that that blog post is quite old (september 2009). Django's DATABASES setting has been updated since 1.2.
The syntax in the blog post was:
settings.configure(DATABASE_ENGINE='sqlite3', DATABASE_NAME='dev.db')
With Django 1.2.X this is surely not correct. This would be the equivalent version:
settings.configure(DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': 'dev.db'
}
})
(sorry for the horrible formatting of the code).
If this still won't work, I'd consider creating a “standard” Django settings file to import. But my bet is on the db settings syntax.
Last update, I swear
Have you tried using django-admin.py again with the new syntax? If so, and still didn't work, a minimal settings.py would be just this:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': 'dev.db'
}
}
You can also keep the original configuration inside dj_tornado.py and use settings.py just to do syncdb.