how to use django markdown in my blog - django

at first I successfully install django markdown
pip install django-markdown
than I add django-markdown in my setting.py file
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'blog',
'django-markdown',
]
then, I change my urls.py like as:
from django.conf.urls import include, url
from django.contrib import admin
from resume import views
urlpatterns = [
url(r'^admin/', include(admin.site.urls)),
url(r'^home/$', views.home, name='home'),
url(r'^blog/', include('blog.urls',namespace='blog',app_name='blog')),
url('^markdown/', include('django_markdown.urls')),
]
I also change my admin.py file like as:
from django.contrib import admin
from .models import Post
from django_markdown.admin import MarkdownModelAdmin
class PostAdmin(admin.ModelAdmin):
list_display = ('title','slug','author','publish','status')
list_filter = ('status','created','publish','author')
search_fields = ('title','body')
prepopulated_fields = {'slug':('title',)}
raw_id_fields = ('author',)
date_hierarchy = 'publish'
ordering = ['status','publish']
# Register your models here.
admin.site.register(Post,MarkdownModelAdmin, PostAdmin)
but, when I start my runserver, django gives me an error like this:
ModuleNotFoundError: No module named 'django-markdown'
how can i solve my problem?

In installed apps you should add django_markdown instead of django-markdown

Related

DoesNotExist at /admin/

DoesNotExist at /admin/
URL matching query does not exist.
I copy code form old study-project and i haven't similar problem in old project.
settings.py INSTALLED_APPS:
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'cutter',
]
admin.py:
from .models import URL
from django.contrib import admin
admin.site.register(URL)
urls.py:
from django.contrib import admin
from django.urls import path, include
urlpatterns = [
path('', include('cutter.urls')),
path('admin/', admin.site.urls),
]
All another functions work.

ModuleNotFoundError: No module named 'polls'

I am following the official Django tutorial on https://docs.djangoproject.com/en/2.2/intro/tutorial01/ but somehow I am not able to run the server as I have created the polls app and added the required urls. When I use the command "py mysite\manage.py runserver" it returns me ModuleNotFoundError: No module named 'polls' error.
Project Folder available at
https://i.stack.imgur.com/bbxfW.png
#views.py
from django.http import HttpResponse
def index(request):
return HttpResponse('<h1><this is a test page</h1>')
#urls.py in polls
from django.urls import path
from . import views
urlpatterns = [
path('', views.index, name='index'),
]
#urls.py in mysite\mysite
from django.contrib import admin
from django.urls import include, path
urlpatterns = [
path('polls/', include('polls.urls')),
path('admin/', admin.site.urls),
]
#settings.py
INSTALLED_APPS = [
'polls',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
]
[1]: https://i.stack.imgur.com/bbxfW.png
Well, I resolved it myself. Polls module was not found because it was created outside the project directory. When I removed it and recreated inside the project directory, it was OK now.
also it may be a good idea to cd into yoru django project so you are only running
python manage.py runserver

Django Cannot Add Model to Admin Site

I can't add new model to django's admin site. There is only one app can display its models and the other apps cannot add their models to admin site.
Here is my settings.py:
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
# Uncomment the next line to enable the admin:
'django.contrib.admin',
# Uncomment the next line to enable admin documentation:
# 'django.contrib.admindocs',
'Home',
'Scope',
'Trend',
'Log',
'Lab',
'Club',
'Article',
'Search',
'page_test',
Here is the urls.py:
from django.conf.urls import patterns, include, url
from cretus import views
# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
# Examples:
# url(r'^$', 'cretus.views.home', name='home'),
# url(r'^cretus/', include('cretus.foo.urls')),
# Uncomment the admin/doc line below to enable admin documentation:
# url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
# Uncomment the next line to enable the admin:
#url(r'^$', include('Home.urls')),
url(r'^$', include('page_test.urls')),
url(r'^page/', include('Home.urls')),
url(r'^search/', include('Search.urls')),
url(r'^test/', include('page_test.urls')),
#url(r'artistsearch/', include('Search.urls')),
url(r'^admin/', include(admin.site.urls)),
url(r'^artscopes/', include('Scope.urls')),
url(r'^trend/', include('Trend.urls')),
url(r'^log/', include('Log.urls')),
url(r'^lab/', include('Lab.urls')),
url(r'^club/', include('Club.urls')),
url(r'^privacy/$', views.privacy, name='privacy'),
url(r'thanks/$', views.thanks, name='thanks'),
url(r'^contest/$', views.contestForm, name='contest'),
url(r'^terms/$', views.terms, name='terms'),
#url(r'^test/$', views.test, name='test'),
#url(r'^(?P<title>[a-zA-Z0-9_-]{0,100})/$', views.getArticleByTitle, name='test'),
#url(r'^article/', include('Article.urls')),
url(r'^article/', include('page_test.urls')),
# Apps
url(r'^tinymce/', include('tinymce.urls')),
url(r'^ckeditor/', include('ckeditor.urls')),
url(r'^sitemap.xml$', views.sitemap, name='sitemap'),
url(r'^googlesearch/$', views.googlesearch, name='googlesearch'),
url(r'^legal/$', views.legal, name='legal'),
url(r'^', views.error, name='error'),
)
Here is one of the admin.py:
from django.contrib import admin
from Lab.models import AttendeeInfo
class AttendeeInfoAdmin(admin.ModelAdmin):
list_display = ('fname', 'lname', 'email', 'video_url', 'package_name')
admin.site.register(AttendeeInfo, AttendeeInfoAdmin)
This problem has been solved. It is because the permission has not been granted to this user. So next time when you found you have done all of the procedures but still cannot find your model in the admin console, you may need to check this user's permission.

Django: adding model to admin site

I dont know what i am doing wrong but i cant add model to my admin .
settings.py
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.admin',
'django.contrib.admindocs',
'RM.cal',
'release',
'south',
)
MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.gzip.GZipMiddleware',
'django_notify.middleware.NotificationsMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
)
TEMPLATE_CONTEXT_PROCESSORS = (
global_settings.TEMPLATE_CONTEXT_PROCESSORS +
('django.core.context_processors.request','django.contrib.messages.context_processors.messages',)
)
admin.py
from cal.models import *
from django.contrib import admin
admin.site.register(Cos)
urls.py
from django.conf.urls.defaults import *
# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
# Example:
# (r'^RM/', include('RM.foo.urls')),
(r'^cal/', include('RM.cal.urls')),
# Uncomment the admin/doc line below to enable admin documentation:
# (r'^admin/doc/', include('django.contrib.admindocs.urls')),
# Uncomment the next line to enable the admin:
(r'^admin/', include(admin.site.urls)),
(r'^site_media/(?P<path>.*)$', 'django.views.static.serve',
{'document_root': 'C:/Users/sg0217297/Desktop/test/tkt_crmt/RM/media'}),
models.py its new field just for testing but i can add it to admin ;/
from django.db import models
from django.contrib import admin
class Cos(models.Model):
name = models.CharField(max_length=400, blank= False , null = True)
def __unicode__(self):
return self.name
Any idea why ??
Thanks for help
E:
Updated urls.py
You need to define an app_label in your class, django only looks 1 level deep for models.py, so:
class YourModel(models.Model):
# whatever
class Meta:
app_label = 'cal'
You can also import the 2nd level models within the init of the module above
try to import indivisual models instead of '*' :
from your_app.models import model1,model2

GAE: django-nonrel: No module named myapp.views

I'm using django-nonrel on google app engine.
I've got this problem when visiting http://localhost:8080/album
Could not import myapp.views. Error was: No module named myapp.views
my urls:
urlpatterns = patterns('',
('^_ah/warmup$', 'djangoappengine.views.warmup'),
('^$', 'django.views.generic.simple.direct_to_template', {'template': 'home.html'}),
(r'^album/$', 'myapp.views.view_albums'),
(r'^admin/', include(admin.site.urls)),
)
my views:
def view_albums(request):
return direct_to_template(request, 'album.html', locals())
Part of Settings:
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.contenttypes',
'django.contrib.auth',
'django.contrib.sessions',
# 'django.contrib.sites',
'djangotoolbox',
# djangoappengine should come last, so it can override a few manage.py commands
'djangoappengine',
)
PROJECT_DIR = os.path.dirname(__file__)
MEDIA_ROOT = os.path.join(PROJECT_DIR, 'media/')
ADMIN_MEDIA_PREFIX = '/media/admin/'
TEMPLATE_DIRS = (os.path.join(os.path.dirname(__file__), 'templates'),)
ROOT_URLCONF = 'urls'
I'm not using django's site framework, the app structure is
myapp
-\dbindexer
-\django
-\djangoappengine
-\djangotoolbox
-\media
-\templates
-__init__.py
-app.yaml
-views.py
-urls.py
-settings.py
-models.py
-manage.py
-cron.yaml
-dbindexes.py
...
I think you are using
from myapp.views import * in urlconf
please try
-- in urlconf
from views import *