2013-07-10 17 views
1

我試圖在Apache服務器上託管的django網站上使用neo4j數據庫。我正在使用neo4django。我遵循http://neo4django.readthedocs.org/en/v0.1.8/index.html中的說明。創建一個節點時,我得到以下錯誤:在apache上使用neo4django

error at /disk/ [Errno 111] Connection refused Request 

我的models.py:

import django.db 
from neo4django.db import models 

class Person(django.db.models.Model): 
name = django.db.models.CharField(max_length=50, null=True, blank=True) 
username = django.db.models.CharField(max_length=50, null=True, blank=True) 
password=django.db.models.CharField(max_length=50, null=True, blank=True) 
email=django.db.models.CharField(max_length=50, null=True, blank=True) 

    class Meta: 
     db_table='lt_profile' 

class Pnode(models.NodeModel): 
    name=models.StringProperty() 
    #more fields 

class Anode(models.NodeModel): 
    art_type=models.StringProperty(max_length=50) 
    mtime=models.StringProperty(max_length=200) 

#relation: 

我的settings.py:

NEO4J_DATABASES = { 
    'default' : { 
     'HOST':'localhost', 
     'PORT': 7474, 
     'ENDPOINT':'/var/www/graph_db' 
    } 
} 

DATABASE_ROUTERS = ['neo4django.utils.Neo4djangoIntegrationRouter'] 

代碼中錯誤發生:

a = Anode.objects.create(art_type='py', mtime=str(file_mtime)) 
a.save() 

我想我需要討論ge在我的port.conf文件在Apache中,但我不知道該怎麼辦。我試過這樣的東西:

ports.conf中聽7474,但沒有運氣。任何幫助將不勝感激。謝謝

+0

python版本:2.7和neo4django版本1.8 –

+1

我認爲你的端點是不正確的 - 它應該是neo4django可以連接的外部路徑。沒有時間做更多的評論。 –

回答

1

@Wes在評論中是正確的 - 您的端點應設置爲相對URL,而不是文件路徑。

From the docs,嘗試'ENDPOINT':'/db/data',這是Neo4j的默認值。

編輯:

建議的一些其他位:

你絕對不需要在你的Apache配置添加任何東西。 Apache從Django提供你的內容,但不能控制你可以從Django訪問哪些端口,它的配置文件只包括外部用戶可以訪問的端口。事實上,如果Apache配置爲在7474上偵聽,並且它與Neo4j位於同一臺服務器上,則其中一個服務器將無法使用該端口。

在您的代碼中,您使用a = Anode.objects.create(...),然後使用a.save()Anode.objects.create()是一個快捷方式

a = Anode(...) 
a.save() 

所以你實際上保存兩次。我會使用其中一種避免不必要地更頻繁地觸擊數據庫。