Django community: RSS
This page, updated regularly, aggregates Django Q&A from the Django community.
-
how to import all the contents from my wordpress blog to my website which i am currently building with pythonn django1.11
I mean to say is i have wordpress webtsite for blogging and i m now planning to build new custom blog from django and i want to import all the contents from the wordpress to new django powered site as i have my own server and hosting wordpress site from that personal server only in hostgator!!?? I sit possible to do that? as if i build new django powered site and it will be basically new start again i will loose all my audience for my previous post !! As i want all my post contents from the wordpress built blog transfered to my django powered blog.!! Please show me some way for this and in detail pls!! -
Django "expected string or buffer " error
I am working on my blog, but when I migrate it gave me an error: "expected string or buffer " error. In the line 22. It is an integral model that collects the view times, I guess maybe it was changed the value in the view.py and that could have trouble modifying models after creating them. So I try to chage default and add other arguments in the view_time, but that does not work. Can someone helps me solve the problem or give me a wise idea to redesign a better database? Here are my codes. models.py, Article contains view time class Article(models.Model): title = models.CharField(max_length=20) content = MarkdownField() date = models.DateField() description = models.TextField(blank=True) article_type = ( ('Learning', ( ('Python', 'python'), ('Java', 'java'), ) ), ('Life', 'life'), ('Other', 'other') ) type = models.CharField(max_length=20, choices=article_type, blank=True) lock = models.BooleanField(default=False) view_time = models.IntegerField(default=1) # line 22 [error occured here] def __str__(self): return self.title class Comment(models.Model): name = models.CharField(null=True, blank=True, max_length=20) comment = models.TextField() auto_date = models.DateField(auto_now_add=True) belong_to = models.ForeignKey(to=Article, related_name="under_comment", null=True, blank=True) def __str__(self): return self.name part of the view.py, When one of the articles is visited, the view_time will be added 1. def blog_content(request, page_num, error_form=None): context = {} form … -
post-get from particle photon to django
i work on photon and django. i send request from photon (which can run .ino files). So i send send "POST" to my localhost ip and free host site's ip and am not able to receive "GET" the value in python/Django. i think i can send successfully from photon but what i should do to get the value ? my temp.ino is : // This #include statement was automatically added by the Particle IDE. #include <HttpClient.h> #include "application.h" HttpClient http; http_header_t headers[] = { { "Content-Type", "application/json" }, { NULL, NULL } }; http_request_t request; http_response_t response; void setup() { Serial.begin(9600); //192.168.1.169:8080 //my free host "heroku" site ip is: 23.23.197.77 request.ip = IPAddress(23,23,197,77); request.port = 8000; } void printResponse(http_response_t &response) { Serial.println("HTTP Response: "); Serial.println(response.status); Serial.println(response.body); } void getRequest() { request.path = "/photon/time"; request.body = ""; http.get(request, response, headers); printResponse(response); } void postRequest() { // here i send value: 22345 to 23.23.197.77 . but cant get it. request.path = "/photon/measurements"; request.body = "{\"measurementType\":\"static\", \"value\": 22345}"; http.post(request, response, headers); printResponse(response); } void loop() { getRequest(); postRequest(); delay(50); } -
related classes of related classes django 1.9
I am building a site that display guides. Each guide has steps. Each step has sub_steps. I have done it with PK like this code. How do I return for example sub_step 3 of step 5 in guide 2? Also I have tried to do the inline admin function to add steps inside the guide and sub_steps inside the steps to keep it organised but can only get it to work with step in guide. How is this done? class Guide(models.Model): guide_title = models.CharField(max_length=200) guide_category = models.CharField(max_length=70) guide_why = models.TextField() guide_how = models.TextField() class Step(models.Model): guide = models.ForeignKey(Guide, on_delete=models.CASCADE) step_title = models.IntegerField(default=1) class Sub_step(models.Model): step = models.ForeignKey(Step, on_delete=models.CASCADE) sub_step_title = models.IntegerField(default=1) sub_step_img = models.ImageField() sub_step_task = models.TextField() sub_step_description = models.TextField() -
Is there a specific way to cancel tasks in django celery
my issue is I have a function that executes every 3 days by means of celery's apply_async. I set a pending order to cancelled if it doesnt get approved in 2 days. The problem is, if the admin reconsiders it and changes the status back to pending, the timer should restart, the expiration doesnt terminate. I'm not sure if celery's .revoke() will specifically cancel just one .expire() call. I don't want them all to stop just one specific. Can anyone help? tasks.py @app.task(name="expire") def expire(order_id): print(order_id) print("this works") try: order = Order.objects.get(id=order_id) print(order) except: print(f"Failed retrieving order object of id {order_id}") return if order.status != "P": return # Place products back to inventory line_items = order.orderlineitems_set.all() for line_item in line_items: product = line_item.product quantity = line_item.quantity product.quantity += quantity product.save() # Cancel order order.status = "C" print(order.status) order.save() views.py class PurchaseView(View): @staticmethod @login_required @customer_required def get(request): cart = Cart(request=request) if not cart.is_approved: print("Cart is not approved") return redirect("/checkout/cart/") customer = Customer.objects.get(user=request.user) order = cart.convert_to_order(customer=customer) cart.reset_cart() print(order.status) expire.apply_async(args=(order.id,), eta=datetime.utcnow() + timedelta(days=3)) context = make_context(request) context["total_price"] = order.total_price return render(request, 'purchase.html', context) -
How can I add a list element on a Python Django website via button?
I am working on a little music website and I already have two albums and their songs. But how can I add a new Album or a new Song to my Database but on the Interface of the website? I have two Textfields for the Album (Artist, Title) and one for the Songs (just title). When you click the button it links you to another page where you can type in the title etc. That's my template for the Album site. The Song site is similar: my views.py for CreateView class AlbumCreate(CreateView): model = Album template_name = 'music/album_form.html' fields = ['artist', 'title'] and my urls.py urlpatterns = [ url(r'^$', views.IndexView.as_view(), name='index'), url(r'^(?P<pk>[0-9]+)/$', views.DetailView.as_view(), name='detail'), url(r'^album-add/$', views.AlbumCreate.as_view(), name='album-add'), url(r'^song-add/$', views.SongCreate.as_view(), name='song-add') and my album_form.html template <form> {% csrf_token %} <div> <h2>Add Album</h2> <input placeholder="Enter Artist size="30"><br><br> <input placeholder="Enter Albumtitle" size="30"><br> </div> </form> <a href="{% url 'music:index' %}"> <button type="submit">Add</button> </a> and here is my index.html template where all the Albums are displayed <ul> {% for album in object_list %} <li><a href = "{% url 'music:detail' album.id %}">{{album.artist}} - {{album.title}} </a> </li> I would like to know if there is a method for saving the objects after sending the data to the … -
RuntimeError: Conflicting 'userprofile_roles' models in application
I am new in django and i have a project based on django 1.6.X and i want to upgrade it to 1.11.X to add some features but when i did it i found many problems and i solved some of them but this one i don't know what to do with it, it gives me when i run it: RuntimeError: Conflicting 'userprofile_roles' models in application 'survey': <class 'survey.models.UserProfile_roles'> and <class 'survey.models.Userprofile_Roles'>. Full error_log: Unhandled exception in thread started by <function wrapper at 0x7f2b1a21b140> Traceback (most recent call last): File "/usr/local/lib/python2.7/dist-packages/Django-1.11.3-py2.7.egg/django/utils/autoreload.py", line 227, in wrapper fn(*args, **kwargs) File "/usr/local/lib/python2.7/dist-packages/Django-1.11.3-py2.7.egg/django/core/management/commands/runserver.py", line 117, in inner_run autoreload.raise_last_exception() File "/usr/local/lib/python2.7/dist-packages/Django-1.11.3-py2.7.egg/django/utils/autoreload.py", line 250, in raise_last_exception six.reraise(*_exception) File "/usr/local/lib/python2.7/dist-packages/Django-1.11.3-py2.7.egg/django/utils/autoreload.py", line 227, in wrapper fn(*args, **kwargs) File "/usr/local/lib/python2.7/dist-packages/Django-1.11.3-py2.7.egg/django/__init__.py", line 27, in setup apps.populate(settings.INSTALLED_APPS) File "/usr/local/lib/python2.7/dist-packages/Django-1.11.3-py2.7.egg/django/apps/registry.py", line 108, in populate app_config.import_models() File "/usr/local/lib/python2.7/dist-packages/Django-1.11.3-py2.7.egg/django/apps/config.py", line 202, in import_models self.models_module = import_module(models_module_name) File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module __import__(name) File "/media/ahmed-mohamed/My Stuff/Work/AgileEngage.Sample/survey/models.py", line 255, in <module> class Userprofile_Roles(models.Model): File "/usr/local/lib/python2.7/dist-packages/Django-1.11.3-py2.7.egg/django/db/models/base.py", line 325, in __new__ new_class._meta.apps.register_model(new_class._meta.app_label, new_class) File "/usr/local/lib/python2.7/dist-packages/Django-1.11.3-py2.7.egg/django/apps/registry.py", line 224, in register_model (model_name, app_label, app_models[model_name], model)) RuntimeError: Conflicting 'userprofile_roles' models in application 'survey': <class 'survey.models.UserProfile_roles'> and <class 'survey.models.Userprofile_Roles'>. Can any one help me with it ? thanks alot. Edit: this is … -
Missing matching query when writing custom views
Because of some form manipulations, I had to write custom views and followed the example in the cookbook. When writing in my view if request.POST: if includeHelper.check_valid(): process = includeHelper.save() request.activation.process = process request.activation.done() return redirect(get_next_task_url(request, request.activation.process)) I get a "Matching Query does not exist" error. I first thought my includeHelper, which is just a class managing formsets etc., returns a process that can not be saved due to some error in my code. However, when I skip the part that involves request.activation if request.POST: if includeHelper.check_valid(): process = includeHelper.save() return HttpResponse("ok") it works. Any ideas? -
How to update a field value on a parent model, based on information on child, when saving
I have an Order:Detail structure on my Django app, and want to be able to save the SUM of my order_detail on my order, when creating one. I tried using the SAVE def override, but it has some kind of delay. Here is my code: class order(models.Model): person = models.ForeignKey(person) total_amt = models.FloatField() def save(self, force_insert=False, force_update=False): self.total_amt=0 for detail in self.oder_detail_set.all(): self.total_amt += detail.detail_amt super(order, self).save(force_insert, force_update) class order_detail(models.Model): order = models.ForeignKey(order) descr = models.CharField(max_length=100) detail_amt = models.FloatField() I want the TOTAL_AMT on the ORDER to be a sum of the DETAIL_AMT on the ORDERDETAIL. What am I doing wrong? Tks -
Differentiating unauthenticated users in custom decorator
Django beginner here. I have been using the inbuilt login_required decorator. I want to override it for certain users who's referral urls match a certain pattern (e.g. all users originating from /buy_and_sell/). My purpose is to show a special login page to just these users, and a generic one to everyone else. I've been looking at various examples of writing custom decorators (e.g. here, here, here and here). But I find the definitions hard to grasp for a beginner. Can someone give me a layman's understanding (and preferably illustrative example) of how I can solve my problem? -
Django Error: 'Document' object has no attribute '_committed'
I'm running the following code which is producing the following error at generated_document.save() : ERROR 'Document' object has no attribute '_committed' CODE def generate_documents(request, survey_id): ''' Generates the documents for this customer based on their survye answers. Saves the document with the customer and the document template ''' survey = Survey.objects.get(id=survey_id) documents = Document.objects.all() for document in documents: doc = DocxTemplate(document.doc) context = { 'organization' : survey.organisation, 'ResponsibleSecurityOfficer' : survey.responsibleSecurityOfficer, 'ResponsibleSecurityOfficerJobTitle' : survey.responsibleSecurityOfficerJobTitle, 'pciCompliant' : survey.pciCompliance, 'hipaaCompliant' : survey.hipaaCompliance, } doc.render(context) doc.save("generated.doc") # get existing document if it exists, else create new try : generated_document = GeneratedDocument.objects.get(survey=survey, document=document) except: generated_document = GeneratedDocument( survey=survey, document=document ) generated_document.doc = doc generated_document.save() messages.success(request, 'Your documents have been generated') return redirect ('home') My associated models are: MODELS class Document (models.Model): name = models.CharField ( verbose_name = 'Title', default = 'Untitled', max_length = 30, ) doc = models.FileField( upload_to = 'documents/' ) def __unicode__(self): return u'%s' % (self.doc) class GeneratedDocument (models.Model): survey = models.ForeignKey(Survey) document = models.ForeignKey( Document, blank=True, null = True) doc = models.FileField( upload_to = 'generated_docs/' ) def __unicode__(self): return u'%s | %s | %s' % (self.survey.organisation, self.document.name, self.doc) I do not understand the error and would appreciate some advice. Thank you -
Django custom file syntax error
I get a syntax error in a cart.py file I created in 'cart' app for basic cart functions if cart_item.menuitem.id = i.id: cart.py: # add an item to the cart def add_to_cart(request): postdata = request.POST.copy() # get menuitem slug from post data, return blank if empty menuitem_slug = postdata.get('menuitem_slug','') # get quantity added, return 1 if empty quantity = postdata.get('quantity',1) # fetch the menuitem or return a missing page error i = get_object_or_404(MenuItem, slug=menuitem_slug) #get menuitems in cart cart_menuitems = get_cart_items(request) menuitem_in_cart = False # check to see if item is already in cart for cart_item in cart_menuitems: if cart_item.menuitem.id = i.id: # update the quantity if found cart_item.augment_quantity(quantity) product_in_cart = True if not product_in_cart: # create and save a new cart item ci = CartItem() ci.menuitem = i ci.quantity = quantity ci.cart_id = _cart_id(request) ci.save() # returns the total number of items in the user's cart def cart_distinct_item_count(request): return get_cart_items(request).count() -
Getting this error in django "ModuleNotFoundError at /myapp/"
I am using django version 11.3. I create a separate HTML template file and import in my views.py file when i run this file it gives me an error. ModuleNotFoundError at /myapp/ No module named 'django.templates' My settings.py file code: TEMPLATES = [ { 'BACKEND': 'django.templates.backends.django.DjangoTemplates', 'DIRS': [os.path.join(BASE_DIR, 'templates')] , 'APP_DIRS': True, 'OPTIONS': { 'context_processors': [ 'django.templates.context_processors.debug', 'django.templates.context_processors.request', 'django.contrib.auth.context_processors.auth', 'django.contrib.messages.context_processors.messages', ], }, }, ] views.py file: from django.http import HttpResponse from django .template import loader from .models import album def myapp(request): all_albums = album.objects.all() template = loader.get_template('myapp/index.html') context = { 'all_albums': all_albums, } return HttpResponse(template.render(context, request)) def detail(request, id): return HttpResponse("<h1>Your requested numbers is: " + str(id) +"<h2>") html file: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>This is list item</title> </head> <body> <ul> {% for a in all_albums %} <li><a href="/myapp/{{ a.id }}">{{ a.artist }}</a></li> {% endfor %} </ul> </body> </html> Directory structure: myapp > templates > myapp > index.html -
Django-import-export facing importing files issue
I am using django-import-export module with django 1.9.5 and python 2.7. I have 2 issues regarding the admin First, when I import xlsx file that contain duplicates, it stop importing and give me errors. I want it to skip these duplicates and continue importing the non-duplicates. Second issue, if I have unique fields and I leave some of these fields empty it gives me error that this fields (all empty fields) are duplicates. -
Django group by date and count per category
Example models class Category(models.Model) name = models.CharField() class CategoryItem(models.Model): category = models.ForeignKey(Category) name = models.CharField() quantity = models.IntField() at = models.DateTimeField() Categories: 1, Category #1 2, Category #2 3, Category #3 Items: ID,NAME,CATEGORY_ID,QUANTITY,AT 1,Item #1,1,100,2017.1.1 2,Item #2,1,200,2017.1.3 3,Item #3,1,300,2017.1.3 4,Item #4,2,400,2017.1.10 5,Item #5,3,500,2017.1.10 How i can annotate this by day and count "quantity" per category Like this 2017.1.1 - Category #1 - Quantity: 100 2017.1.3 - Category #1 - Quantity: 500 2017.1.10 - Category #2 - Quantity: 400 - Category #3 - Quantity: 500 -
how to access Django form fields through HTML
I have created models.py, forms.py, views.py & registeration.html. At the moment in registeration.html I am directly importing the django form like {{reg_form.as_p}}, I can also do it in following two ways: {{ form.as_table }} or {{ form.as_ul }}. what I want is to have a real control over the fields to be displayed. Meaning to say some fields may be tabular, some may be list etc with specific css. What I tried was is mentioned below: <div class="field-label">Full Name <span class="req">*</span></div> <input type="text" id = {{form.id_FullName}} name={{form.FullName}}>. In my models.py I have FullName = models.CharField(max_length = 100) The above way didnt work, I want some way to access the django fields in HTML. -
Pass context to pagination class in Django Rest Framework
I have my custom pagination class. class BasicPagination(PageNumberPagination): page_size = 3 page_size_query_param = 'page_size' max_page_size = 20 def get_paginated_response(self, data): has_next, has_previous = False, False if self.get_next_link(): has_next = True if self.get_previous_link(): has_previous = True meta = collections.OrderedDict([ ('page', self.page.number), ('has_next', has_next), ('has_previous', has_previous), ]) ret = collections.OrderedDict(meta=meta) ret["results"] = data return Response(ret) Also I have a generics.ListCreateAPIView class, which has custom queryset method and pagination_class = BasicPagination. I wanna pass self.kwargs.get("obj_type") to pagination class so that it displays obj_type not results. Here is my class view. How can I pass self.kwargs to pagination class? class Translation(ListCreateAPIView): pagination_class = BasicPagination serializer_class = TranslationStepSerializer def get_queryset(self): api_controller = ApiController.load() obj_type = self.kwargs.get("obj_type") pk = self.kwargs.get("pk") data = api_controller.get_translation(obj_type, pk) return data if not None else None -
TransactionManagementError:This is forbidden when an 'atomic' block is active while running unit test cases
I am getting this error while I am trying to run unit test case using pytest. Its working fine in my project but raised an error while running test case. my code is as fallows: def saveEvents(request, request_data): transaction.set_autocommit(autocommit=False) try: # here is my code except Exception as inst: transaction.rollback() # code transaction.commit() return something I read all the solutions of this type of questions, but i am getting why its not working with pytest. Please help. Thanks. -
Real time plot on django based on bokeh library but without using bokeh server
I am try to plot real time figures based on Bokeh library on Django. What I am not getting is how can I make real time plots? There is one example here: Streaming two line graphs using bokeh but this is based on bokeh server, and I don't want to use bokeh server. I want to plot using django views. Please guide me! -
django webpack loader: React app hot reload failure
Some context: I am developing a Django application, and I would like to integrate a React component in a template. I am new to React, not so to Django. So, I am trying to setup a React dev environment, with hot reloading of the React component inside my Django template. I followed these tutorials : http://owaislone.org/blog/webpack-plus-reactjs-and-django/ https://www.botzeta.com/post/11/ (looks like it's just the first one updated to the most recent version of webpack) And it seems quite fine, since I have the following feedbacks when I modify and save my js source code: in npm console: > node server.js Listening at 0.0.0.0:3000 Hash: ecfef9f1eea0022319ef Version: webpack 3.3.0 Time: 6294ms Asset Size Chunks Chunk Names main-ecfef9f1eea0022319ef.js 1.37 MB 0 [emitted] [big] main [26] ./node_modules/react/react.js 56 bytes {0} [built] [77] (webpack)/hot/log.js 1.04 kB {0} [built] [141] (webpack)/hot/emitter.js 77 bytes {0} [built] [142] ./node_modules/react-dom/index.js 59 bytes {0} [built] [169] ./assets/js/App.js 779 bytes {0} [built] [170] multi react-hot-loader/patch webpack-dev-server/client?http://localhost:3000 webpack/hot/only-dev-server ./assets/js/index.js 64 bytes {0} [built] [171] ./node_modules/react-hot-loader/patch.js 41 bytes {0} [built] [172] ./node_modules/react-hot-loader/lib/patch.js 209 bytes {0} [built] [293] (webpack)-dev-server/client?http://localhost:3000 5.83 kB {0} [built] [302] ./node_modules/loglevel/lib/loglevel.js 6.74 kB {0} [built] [335] (webpack)-dev-server/client/overlay.js 3.6 kB {0} [built] [340] (webpack)/hot nonrecursive ^\.\/log$ 170 bytes {0} [built] [342] (webpack)/hot/only-dev-server.js … -
ZOHO smtp SMTPAuthenticationError at / (535, 'Authentication Failed') Django app
I am trying to establish a connection via shell on the VPS with this code: import smtplib from email.mime.text import MIMEText sender = 'my zoho email' recipient = 'my gmail account email' msg = MIMEText("Message text") msg['Subject'] = "Sent from python" msg['From'] = sender msg['To'] = recipient server = smtplib.SMTP_SSL('smtp.zoho.com', 465) # Perform operations via server server.login('my zoho account email', '*********') All the credentials are correct, since I am login in successfully to my account at https://www.zoho.eu/mail/ When i try to login with: server.login('my zoho account email', '*********') I get SMTPAuthenticationError and the stack trace shows: self.connection.login(force_str(self.username), force_str(self.password)) ... raise SMTPAuthenticationError(code, resp) my settings.py is: EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend' EMAIL_USE_TSL = True EMAIL_PORT = 465 EMAIL_HOST = 'smtp.zoho.com' EMAIL_HOST_USER = '**********' EMAIL_HOST_PASSWORD = '*********' There are numerous threads about this on the web but, not even one has an answer about it. Their support doesn't answer for third day now... I am using NGINX and the default configuration is not set for https:// but my custom configuration is and the website is running over https://. Edit: If I try to connect over port 587 with: server = smtplib.SMTP_SSL('smtp.zoho.com', 587) I get: SSLError: [SSL: UNKNOWN_PROTOCOL] unknown protocol (_ssl.c:590) -
Django error "There is no South database module 'south.db.mysql' for your database"
I am new in django and i have a project based on django 1.6 and i want to add some new features in it but when i upgrade it to the latest version and run the project it gives me this error: There is no South database module 'south.db.mysql' for your database. Please either choose a supported database, check for SOUTH_DATABASE_ADAPTER[S] settings, or remove South from INSTALLED_APPS. This is my base settings.py DATABASES = { 'default': { 'ENGINE': 'django.db.backends.mysql', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'. # 'ENGINE': 'mysql', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'. 'NAME': 'sample', # Or path to database file if using sqlite3. 'USER': 'root', # Not used with sqlite3. 'PASSWORD': 'root', # Not used with sqlite3. 'HOST': '127.0.0.1', # Set to empty string for localhost. Not used with sqlite3. 'PORT': '3306', # Set to empty string for default. Not used with sqlite3. } } 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', 'south', 'survey', 'django_tables2', 'email_sender', 'fake_it', 'client_admin', 'instance_management', 'user_management', ) When i searched for it i found many solution like … -
Django rest api not accepting raw data
I am trying to create a user through django rest framwork API. my views.py class MyUserViewSet(viewsets.ModelViewSet): queryset = get_user_model().objects.all() serializer_class = UserSerializer serializer.py class UserSerializer(serializers.ModelSerializer): class Meta: model = get_user_model() fields = '__all__' urls.py router.register(r'user', views.MyUserViewSet, 'users') User saving is working fine when I submit data as form-data. But when I tried to do that using raw data, am getting the following error. "groups": [ "Expected a list of items but got type \"unicode\"." ], Input I am passing as raw data is { "password":"12345678", "email":"mymail@yopmail.com", "groups":"1", "first_name":"Arun", "last_name":"Joshi" } I am using postman to test this API. -
Django ImproperlyConfigured urls.py file
I'm working on a project from the Python Crash Course Book and Django is throwing an error with this code: from django.conf.urls import include, url from django.contrib import admin urlpatterns = [ url(r'^admin/', admin.site.urls), url(r'', include('learning_logs.urls', namespace='learning_logs')), ] The error is: django.core.exceptions.ImproperlyConfigured: The included URLconf '<module 'learning_logs.urls' from '/Users/sethkillian/Desktop/learning_log/learning_logs/urls.py'>' does not appear to have any patterns in it. If you see valid patterns in the file then the issue is probably caused by a circular import. I added the include import since it wasn't found at first. One thing I noticed was that include was there by default in the book, but not in my project. Has Django gotten rid of it since? Here is the learning_logs url.py: """Defines URL patterns for learning_logs.""" from django.conf.urls import url from . import views xurlpatterns = [ # Home page url(r'^$', views.index, name='index'), ] -
I have a list of objects and would like to return an attribute with another attribute
If my objects were {(title: 'one', content: 'foo'), (title: 'two', content: 'bar'} how would I go about getting 'for' and 'bar' into my template something like this {% for content in content_list where content.title='one'} {{ content.content }} resulting in 'foo' {% for content in content_list where content.title='two'} {{ content.content }} resulting in 'bar'